有不同的方法,这里是一个:从你的第一个 viewController:
NSDictionary* dict = [NSDictionary dictionaryWithObject:
[NSNumber numberWithInt:theIdYouWantToSend]
forKey:@"index"];
[[NSNotificationCenter defaultCenter] postNotificationName: @"getID" object: dict];
现在从新的视图控制器(detailViewController),在 viewDiDLoad 方法中:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(getID:) name:@"getID" object:nil];
并创建方法:
-(void)getID:(NSNotification*)notification{
NSDictionary* dict = (NSDictionary*) notification.object;
}
您可以轻松地从字典中获取 ID
myId = [dict objectForKey:@"index"];