Tuesday 15 July 2014

objective c - Add objects to an NSMutableArray in my base view controller from a second view controller, ios -


All I am looking for in the morning is how to do this I have 2 view controller . You can push another view controller ( ViewControllerB ) from the root view controller ( ViewControllerA - which is a table view controller).

In ViewControllerB , there are two fields: Contacts & amp; TextBody When a user is done, they can click on "Add" and then they will go back to ViewControllerA . Now what I am trying to do, every time this process is done, all the information that is received from ViewControllerB has been added which is a cell in ViewControllerA Goes in. Users can then add as many cells as they can.

Although what I can not do, it is getting information across the view controller. I see everyone using Appar, Eklavya, Protocol, Sharing properties etc. in the morning! But I'm still stuck.

What I want to do, but not every time the user contacts at ViewControllerB , contact & amp; The texts are placed in an array. This array is then placed in another array that keeps all the small arrays created by the user? If you have any ideas, or have a similar / sample code or a link to the tutorial, it will be highly appreciated!

Try this type using the delegate method

ParentViewController.h

  #import & lt; UIKit / UIKit.h & gt; @ Interface parent wave controller: UIViewController {NSMutableArray * dataArray; } - (zero) passdata: (NSMutableArray *) array; @end   

ParentViewController.m #import "ParentViewController.h" #import "ChildViewController.h" @implementationParentViewController - (Zero) viewDidoadload [[Super Viewedload]; // Start the volatile array of dataArere = [[NSMUTPABARROL] INIT]; } - (IBAction) btnGoToSecondView: (ID) Sender {ChildViewController * secondVC = [[ChildViewController alloc] initWithNibName: @ "ChildViewController" bundle: zero]; second. [Self-present ViewController: animated secondcv: yes complete: zero]; } - (zero) passdata: (NSMutableArray *) array {[Data array ad: array]; NSLog (@ "Data Passed =% @", DataAire); } @end

Child Week Controller.

  #import & lt; UIKit / UIKit.h & gt; #import "ParenViewController.h" @Category ParentViewController; @ Interface childview controller: UIViewController {NSMutableArray * tempArray; } @property (strong, non-primitive) IBotlicate utitisfield * TSTCact; @property (strong, non-monom) IBotlet Uitfestfield * testtistbody; @protecti (nanatomic, assign) parent vieu controller * representative; @end   

ChildViewController.m

  @implementationChildViewController - View (zero) viewDidload {[Super Viewedload]; // Start shaky array TempArray = [[NSMutableArray alloc] init]; } - (IBAction) btnPassDataBack: (ID) sender {if ([self.delegate responds to the secretary: @selector (passData :)) {[tempArray addObject: _txtContact.text]; [TempArray addObject: _txtTextBody.text]; [Self. Delegate Password: Temperare]; } [Self-captured scene controller permission: Yes complete: zero]; } - (zero) viewDidUUplet {[Self-settextcom: zero]; [Self-settytistabody: blue]; [Super viewload]; } @ And   

with storyboard

If you are using the storyboard, then create a parent ViUI controller Segue Narrow Controller and give it a Then use the following code to set up the representative

  /    To see the child and to set up the representative to call segue - (zero) Ready FORSegue: (UIStoryboardSegue *) Segu Sender: (ID) {If ([segue.identifier is Akwatut string: @ "shows Child Viyu"]) {ChildViewController * childVC = segue.destinationViewController; ChildVC.delegate = self; Use the following code to reject back on ParentViewController (from my sample)  
  - (IBAction) btnPassDataBack: (id) sender {if ([auto responds.] TEL: @Selector (Passdaata :)) {{tempArray addObject: _txtContact.text]; [TempArray addObject: _txtTextBody.text]; [Self. Delegate Password: Temperare]; } [Self. Navigation Controller PopToRootViewControllerAnimated: Yes]; }    

No comments:

Post a Comment