我尝试使用情节提要从一个 ViewController 到另一个进行转场,但它引发了异常。
segues 仅适用于 NavigationControllers 吗?当我以这种方式尝试时,它起作用了。
我尝试使用情节提要从一个 ViewController 到另一个进行转场,但它引发了异常。
segues 仅适用于 NavigationControllers 吗?当我以这种方式尝试时,它起作用了。
如果 aSegue是从一个ViewController到另一个创建的,那么您需要以编程方式执行它,因为只有诸如视图之类的可视元素才能响应用户事件,因此如果没有用户交互,就无法ViewController知道何时执行 a Segue。
以下是如何以编程方式进行操作。
Segue在 Interface Builder 中设置标识符。
调用[self performSegueWithIdentifier:@"MySegueIdentifier" sender:nil];以响应事件,即按钮TouchUpInside来执行它。
这篇文章有更多信息: Segue implementation via code
注意:如果您不使用NavigationController,则不能使用 PushSegue转换,因为这需要NavigationController. 您仍然可以使用Modal过渡类型,或者Custom如果您想提出自己的过渡。
如果您将 ViewControllers 嵌入到UINavigationController使用 Storyboard from ViewControllerAto 中ViewControllerB:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"showDetail"])
{
UINavigationController *navController = (UINavigationController *)segue.destinationViewController;
ViewControllerB *viewControllerB = (ViewControllerB *)navController.topViewController;
// Pass data (for example a NSString object)
viewControllerB.aString = myString;
}
}