如何切换段使用

How to switch segment using

为了不重复,一直到现在才问,试了一整天。所以我知道之前有人问过,但是 none 帮助了我。我在使用故事板时遇到了问题,而且越来越混乱。

我在互联网上发现使用 segues 并覆盖方法 performSegueWithIdentifier:sender : 会有我,我试过了。我将其实现为:

- (IBAction)segmentChanged{
    if([segmentedControl selectedSegmentIndex] == 0)
        [self performSegueWithIdentifier:@"Doviz" sender:self];
    else
        [self performSegueWithIdentifier:@"Altin" sender:self];
}

这是我的故事板:

请注意,我使用的是推送方法而不是嵌入、模态和自定义,并且不是将它们连接到 segmentedController 而是连接到视图。也许也可能有问题。 最后,当我尝试 运行 我的应用程序时,出现错误:

Could not find a navigation controller for segue 'Altin'. Push segues can only be used when the source controller is managed by an instance of UINavigationController.

我是新手,正在学习 Xcode 直到 1 周,所以如果你能给我一个详细的答案,我将不胜感激。

设置故事板,使其看起来像这样:

确保在属性检查器 (Command+Option+4) 中为每个 segue 提供适当的标识符。

请记住,使用分段控件推送视图控制器不是标准的 UI 范例。使用常规 UIButton 控件可能更合适。