I think I'm following how delegation works, here's the tutorial I followed, but I'm messing up somewhere. I'm expecting my delegate to NSLog but it's not. Can anyone find out what am I missing or doing wrong?
My MainViewController.h:
@interface MainViewController : UITableViewController < AddClassDelegate >
MainViewController.m:
- (void)cancelAddingClass {
NSLog(@"Canceled Yo");
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
/*
When a row is selected, the segue creates the detail view controller as the destination.
Set the detail view controller's detail item to the item associated with the selected row.
*/
if ([[segue identifier] isEqualToString:@"addClassSegue"]) {
UINavigationController *nc = (UINavigationController *)segue.destinationViewController;
AddClassViewController *addClassVC = (AddClassViewController *)[nc.viewControllers objectAtIndex:0];
addClassVC.delegate = self;
}
My modal view controller AddClassViewController.h:
@protocol AddClassDelegate <NSObject>
- (void)cancelAddingClass;
@end
@interface AddClassViewController : UITableViewController
@property (weak, nonatomic) id< AddClassDelegate > delegate;
- (IBAction)cancelButtonPressed:(id)sender;
AddClassViewController.m:
@synthesize delegate;
- (IBAction)cancelButtonPressed:(id)sender {
[self.delegate cancelAddingClass];
}
cancelButtonPressed:
is hooked up to the modal view's Cancel button in Storyboard.