我正在使用XCode 4.2开发基于故事板的应用程序。我是故事板的新手,在此之前我曾经通过创建一个类的新实例来切换视图:
if (x==1)
{
theClass *theView ;
theView= [[theClass alloc] initWithNibName:nil bundle:nil];
[theView setText:theText];
[reader presentModalViewController:theClass animated:YES]; //where reader is an instance of the ZBar library
}
使用故事板,这是我正在尝试的代码:
if (x==1)
{
[self performSegueWithIdentifier: @"theNewView" sender: self];
}
然后:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"theNewView"])
{
[[segue destinationViewController] setText:theText];
[reader presentModalViewController:[segue destinationViewController] animated:YES];
}
}
我确保链接很好并且调用了prepareforsegue
方法,但即使使用此代码,新视图也没有被加载?
答案 0 :(得分:1)
不要在presentModalViewController
方法中调用prepareForSeque
- 此方法用于将信息传递给新的视图控制器。
请参阅post。
有用的学习weblog post,用于开始使用故事板。