找到你要的答案

Q:Pass data between view controller

Q:在视图控制器之间传递数据

I have this code in my appdelegate but only when I add the line loginViewController.fnameText = @"Text"; My application crashes while if I remove it all works very well, however for me it is very important to pass this line, you have a solution? Thank you for your reply

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main_iPhone_47" bundle:nil];
DEMOSearchVideosViewController *loginViewController = [storyboard instantiateViewControllerWithIdentifier:@"searchViewController"];
loginViewController.fnameText = @"Text"; // Not wroking -- crash
[self.window makeKeyAndVisible];
[self.window.rootViewController presentViewController:loginViewController animated:YES completion:NULL];

I have this code in my appdelegate but only when I add the line loginViewController.fnameText = @"Text"; My application crashes while if I remove it all works very well, however for me it is very important to pass this line, you have a solution? Thank you for your reply

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main_iPhone_47" bundle:nil];
DEMOSearchVideosViewController *loginViewController = [storyboard instantiateViewControllerWithIdentifier:@"searchViewController"];
loginViewController.fnameText = @"Text"; // Not wroking -- crash
[self.window makeKeyAndVisible];
[self.window.rootViewController presentViewController:loginViewController animated:YES completion:NULL];
answer1: 回答1:

Try to print the "loginViewController" object. It should not be non-null. Also, "fnameText" should be declared as a writable property in "DEMOSearchVideosViewController" class. Because you are trying to set a property on the instance.

尝试打印“loginviewcontroller”对象。它不应该是非空的。同时,“fnametext”应该声明为可写的属性在“demosearchvideosviewcontroller”类。因为您试图在实例上设置属性。

ios  objective-c  uiviewcontroller  uistoryboard