Basically I have two View Controllers: a master and a detail. I'd like for a string inputted in the detail controller to be displayed in a table in the master. In the master controller
I have:
- a NSMutableArray property called names
- a prepareForSegque method that delegates back
a method to get the string from the 2nd controller:
-(void) detailViewControllerAdd:(DetailViewController *)detailViewController{
[self.names addObject:detailViewController.name]; [self dismissViewControllerAnimated:YES completion:nil]; }
and a UITableView:
-(UITableViewCell *) tableView: (UITableView *) tableView cellForRowAtIndexPath:(NSIndexPath *) indexPath{ UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"]; cell.textLabel.text = self.names[indexPath.row]; return cell; } -(NSInteger) tableView: (UITableView *) tableView numberOfRowsInSection: (NSInteger) section { return self.names.count; }
In my second ViewController (detail) I have a textfield and an "add" button. I'd like for the textfield text to be added into the table rows of the master view controller.
-(IBAction)addButton: (id)sender
{
self.name = self.nameTextField.text;
[self.delegate detailViewControllerAdd:self];
}
Sorry if that's confusing, I'm trying to keep it as simple as possible. I know the names are being added fine because I can see them in NSLog
. I've also tried looking up people's suggestions but [tableView reloadData]
doesn't work at all, and [self.tableView]
doesn't even exist.
Any help or advice is greatly appreciated. Also, the segue action is 'modal' if that helps.