-1

I am stuck with a problem and can't find a decent solution. I am trying to add a name in parent ViewController and show them in a UITableView but to add a new name I go to a AddVC where I add a name via a UITextField and I want to add the name in the NSMutableArray from the parentVC.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
  • You want to add the name in a view controller, and have the name passed back to the parent controller? – user1947561 Jul 12 '14 at 15:28
  • yes . i want to add a object in childVC and then show it in ParentVC – SIB1234 Jul 12 '14 at 16:52
  • You code the table view's `dataSource` delegate so that it refers to the NSMutableArray for it's row values, then, after updating the array with a new value, you signal `reloadData` to the table view. – Hot Licks Jul 12 '14 at 20:05

2 Answers2

0

Let me restate what I think you're asking: You have a ParentVC and you want to segue to a ChildVC that will present a UITextField to enter a name. Once the name is entered, you want to return the name back to the ParentVC. If this is correct then within your ChildVC prepareForSegue method:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
      // if you're using a nav controller (modal)
      //UINavigationController *navController = (UINavigationController *)segue.destinationViewController;
      //ParentVC *destinationVC = (ParentVC *)navController.topViewController;

      // if you're not using a nav controller (push)
      ParentVC *destinationVC = (ParentVC *)segue.destinationViewController;

      // assuming you have a public property in your ParentVC.h such as:
      // @property (strong, nonatomic) NSString *theNewName;

      destinationVC.theNewName = myAddNameTextField.text;
}
Wizkid
  • 1,015
  • 10
  • 10
-1

Take an NSMutableArray as a property in your AppDelegate . Always fetch the Array from AppDelegate. If you add something. Just add in this global mutable array. This way it won't matter where you add object in array and where from you fetch .

rihekopo
  • 3,241
  • 4
  • 34
  • 63