[英]iOS: Passing data between View Controllers
I'm using Facebook API, and when the user select a place (CheckIn), I want to open another view and pass this place (FBGraphPlace), but in the "SecondViewController" the variable is null when the method "viewDidLoad" is executed. 我正在使用Facebook API,并且当用户选择一个位置(CheckIn)时,我想打开另一个视图并传递该位置(FBGraphPlace),但是在“ SecondViewController”中,当执行方法“ viewDidLoad”时该变量为null 。 When the user select the place:
当用户选择地点时:
if (secondViewController == nil)
{
SecondViewcontroller *secondViewcontroller =
[[SecondViewcontroller alloc]
initWithNibName:NSStringFromClass([SecondViewcontroller class])
bundle:[NSBundle mainBundle]];
self.secondViewcontroller = secondViewcontroller;
}
// How you reference your navigation controller will
// probably be a little different
UIBarButtonItem *newBackButton = [[UIBarButtonItem alloc] initWithTitle: @"Back" style: UIBarButtonItemStyleBordered target: nil action: nil];
[[self navigationItem] setBackBarButtonItem: newBackButton];
secondViewController.place = self.selectedPlace;
[self.navigationController
pushViewController:self.secondViewcontroller
animated:YES];
您应该先执行pushViewController,然后分配place变量
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.