ios - 无法触发 segue

标签 ios xcode storyboard uistoryboard uistoryboardsegue

因为我使用的是 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 并从代码中调用它:

  1. 在 Storyboard中创建两个 View Controller 。
  2. 控制从源场景中的 View Controller 图标拖动到目标场景。
  3. 选择合适的转场类型。
  4. 在检查器中,为 segue 分配一个标识符。
  5. 在运行时,从源 View Controller 调用

    [self performSegueWithIdentifier:<#identifier#> sender:nil];

  6. 覆盖源 View Controller 中的 -[UIViewController prepareForSegue:sender:] 以在源 Controller 和目标 Controller 之间传递状态。

顺便说一句,-[UIStoryboardSegue initWithIdentifier:source:destination:] 方法供您在创建将从 Storyboard 中实例化的自定义 segues 子类时覆盖。像这样直接创建 Storyboard segue 实例是不适用的。

关于ios - 无法触发 segue,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14887589/

相关文章:

ios - 在 iOS 的 UITextField 中允许单个数字

iphone - 如何在 CAShapeLayer(Rounded-Recr cornered UIView) 上设置 maskToBounds 效果?

ios - 如何设置 UIPickerView 的默认值

ios - 如何在 Storyboard/ Nib 中查找 Xcode 中特定颜色的对象

xcode - 存档选项在 xcode 4.5.2 中呈灰色

ios - Xcode 11 在 bundle NSBundle 中找不到名为 'Main' 的 Storyboard

iphone - 在 Xcode 中设置事件可执行文件

iphone - 处于暂停状态的应用程序的 NSNotificationcenter

ios - UIViewController 不从 Storyboard 中呈现

iOS Storyboarding App-Wide 元素(持久性侧边栏)