你可以用NSNotifications来做到这一点。
#define ReloadMasterTableNotification @"ReloadMasterTableNotification"
在你MasterViewController的viewDidLoad中:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reloadMasterTable:) name:ReloadMasterTableNotification object:_detailViewController];
在MasterViewController的dealloc的,如果你正在使用ARC:
[[NSNotificationCenter defaultCenter] removeObserver:self name:ReloadMasterTableNotification object:nil];
当你想使你的更新的detailViewController通知MasterViewController:
- (IBAction)onButtonPress {
NSIndexPath *path = [NSIndexPath indexPathForRow:indexToUpdate inSection:0];
NSDictionary *dict = [[NSDictionary alloc] initWithObjectsAndKeys:path, @"IndexPath", nil];
[[NSNotificationCenter defaultCenter] postNotificationName:ReloadMasterTableNotification object:self userInfo:dict];
}
- (void)reloadMasterTable:(NSNotification *)notification {
NSDictionary *dict = [notification userInfo];
NSIndexPath *path = [dict objectForKey:@"IndexPath"];
// update MasterViewController here
}
希望有帮助!