Making APP for IOS 6 - I have a mainViewController that when tap on button a new modalViewController is presented. That modalViewController has a tableView. When user taps on a cell I want to take a value of that cell and assign it to variable on mainViewController.
The problem is that I always get NULL when I output it in viewDidAppear method.
This is delegate method in modalViewController:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSMutableString *event_id = [[self.events valueForKey:@"event_id"] objectAtIndex:indexPath.row];
NSLog(@"EVENT ID = %@", event_id); //This gives me actuall ID
[self.presentingViewController dismissViewControllerAnimated:YES completion:^{
[self.mainViewController setEventID:event_id];
}];
}
If you see I use completion block to set it. In my mainViewController I have a property of eventID. In my modalViewController i also have
@class MainViewController
@interface ModalViewController : UITableViewController <UITableViewDataSource, UITableViewDelegate>{
IBOutlet UITableView *eventsTable;
}
@property (strong, nonatomic) MainViewController *mainViewController;
@end
For some reason I am getting eventID always NULL when I try to output it in viewDidAppear but it does output it when I first set it. What am I missing there??
Any help would be very appreciated.
EDIT:
In my MainViewController I already have other delegates set like this:
@interface MainViewController : UIViewController <UICollectionViewDataSource, UICollectionViewDelegate, UIAlertViewDelegate, CLLocationManagerDelegate>
Using protocol delegates approach, how would I add my custom delegate declaration there like ModalViewControllerDelegate.