I have the second view controller presenting itself as modal in this example:
In the second view controllers h file:
@protocol SecondViewControllerDelegate
- (void)addItemViewController:(id)controller didFinishEnteringItem:(NSString *)item;
@end
@interface SecondPageViewController : UIViewController
{
NSString *previouslyTypedInformation;
}
@property (weak, nonatomic) IBOutlet UITextView *textView;
@property (nonatomic) NSString *previouslyTypedInformation;
@property (nonatomic, weak) id delegate;
In the second view controllers m file make sure to synthesize properties and add then add this:
- (IBAction)done:(id)sender
{
NSString *itemToPassBack = self.textView.text;
NSLog(@"returning: %@",itemToPassBack);
[self.delegate addItemViewController:self didFinishEnteringItem:itemToPassBack];
//dismiss modal view controller here
}
Then in the first view controllers h file set it as delegate:
@interface FirstPageViewController: UIViewController
@property (nonatomic) NSString *returnedItem;
Then in the first view controller's m file synthesize and add the method:
- (void)addItemViewController:(SecondPageViewController *)controller didFinishEnteringItem: (NSString *)item
{
//using delegate method, get data back from second page view controller and set it to property declared in here
NSLog(@"This was returned from secondPageViewController: %@",item);
self.returnedItem=item;
//add item to array here and call reload
}
Now you have the text of what was returned! You can add the string to your array in the first view controller's viewDidLoad and call
[self.tableView reloadData];
and it should work.