因为我使用的是 tapku 日历,所以我想在按下日期时触发手动 segue。所以我实例化了我想要转入的 View Controller ,转入,然后执行转入。
DisplayScheduleViewController *vc = [[DisplayScheduleViewController alloc] init];
mySegue = [[UIStoryboardSegue alloc] initWithIdentifier:@"Day G" source:self destination:vc];
[self performSegueWithIdentifier:@"Day G" sender:self];
}
但是,一旦按下日期,程序就会崩溃,这是异常消息:
由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“Receiver () 没有标识符为‘Day G’的 segue”
同样在运行程序之前,我在 Storyboard 中收到了这条警告消息:
场景由于缺少入口点而无法访问,并且没有通过 -instantiateViewControllerWithIdentifier: 进行运行时访问的标识符。
你知道如何让它发挥作用吗?
谢谢
最佳答案
以下是如何在 Storyboard中连接一个 segue 并从代码中调用它:
- 在 Storyboard中创建两个 View Controller 。
- 控制从源场景中的 View Controller 图标拖动到目标场景。
- 选择合适的转场类型。
- 在检查器中,为 segue 分配一个标识符。
在运行时,从源 View Controller 调用
[self performSegueWithIdentifier:<#identifier#> sender:nil];
覆盖源 View Controller 中的 -[UIViewController prepareForSegue:sender:] 以在源 Controller 和目标 Controller 之间传递状态。
顺便说一句,-[UIStoryboardSegue initWithIdentifier:source:destination:] 方法供您在创建将从 Storyboard 中实例化的自定义 segues 子类时覆盖。像这样直接创建 Storyboard segue 实例是不适用的。
关于ios - 无法触发 segue,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14887589/