I’m trying to pass an object between 2 VCs, from a popover to the detail view of split view controller.
I think I need to use NSNotificationCenter.
I tried this but can’t seem to get it to work.
In didSelectRow of popover
[[NSNotificationCenter defaultCenter] postNotificationName:@"PassObject" withObject:objectToPass];
In detail VC
- (void) didReceiveNotificationPassObject:(NSNotification*)notification
{
YourObjectClass *theObject = (YourObjectClass*)notification.object;
}
- (void)viewDidLoad
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didReceiveNotificationPassObject:) name:@"PassObject" object:nil];
}
Probably just a typo when entering the question but in the first line where you post the notification
the method signature is wrong – it should be ‘object:objectToPass’ not ‘withObject:objectToPass’. The line you have there will compile with a warning and crash at runtime.
Aside from that all the logic seems fine.