Define a delegate method in NewViewController that is called when the button is clicked, passing the textField content to the HomeViewController. The HomeViewController implements the delegate method and can then update the books collection as appropriate. E.g.:
NewViewController.h
// Define the delegate method(s)
@protocol NewViewControllerDelegate <NSObject>
-(void)addedTitle:(NSString *)text;
@end
@interface NewViewController : UIViewController
// Declare the delegate property
@property (nonatomic, weak)id <NewViewControllerDelegate>delegate;
// other declarations...
@end
NewViewController.m
#import "NewViewController.h"
@interface NewViewController ()
@end
@implementation NewViewController
// other implementation code...
-(IBAction)buttonTapped:(id)sender{
[self.delegate addedTitle:textField.text];
}
@end
HomeViewController.h
#import <UIKit/UIKit.h>
#import "NewViewController.h"
// Note <NewViewControllerDelegate> on next line
@interface HomeViewController : UIViewController <NewViewControllerDelegate>
// other declaration code...
@end
HomeViewController.m
#import "HomeViewController.h"
@interface HomeViewController ()
@end
@implementation HomeViewController
-(void)viewDidLoad{
[super viewDidLoad];
myNewViewController.delegate = self;
}
// other implementation code...
#pragma mark - NewViewController delegate methods
// Implements the delegate callback
-(void)addedTitle:(NSString *)title{
[self.books addObject:title];
}
@end