我有一个简单的代码来获取一个整数并将其传递给下一个视图,但int总是在另一个视图中以0结尾。我知道它不是变量的问题,因为它在主视图上变成了真正的int。这是我的代码:
AnswerViewController *ansViewController = [[AnswerViewController alloc] initWithNibName:@"AnswerViewController" bundle:nil];
ansViewController.num = theNum;
UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UIViewController *mainView = [storyBoard instantiateViewControllerWithIdentifier:@"ansView"];
[self presentViewController:mainView animated:YES completion:nil];
答案 0 :(得分:1)
这是正确的方法:
//Initialize the storyboard
UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
//initialize the ViewController
AnswerViewController *ansViewController =
[storyBoard instantiateViewControllerWithIdentifier:@"AnswerViewController"];
//Assign the value to the controller property
ansViewController.num = theNum;
//Finally present the view Controller
[self presentViewController:ansViewController animated:YES completion:nil];