【问题标题】:Perform segue of view from NIB subview button从 NIB 子视图按钮执行视图序列
【发布时间】:2014-05-14 04:02:44
【问题描述】:

我有一个主视图(包含配置文件的表格视图),它有一个导航控制器。在导航栏中,我有一个“菜单”栏按钮。当用户单击栏按钮时,菜单视图将作为子视图添加到主视图。这个菜单视图(它是一个子视图)有一个按钮。此按钮将用于连接到故事板中的另一个视图(不是子视图)。

我的菜单视图的 .m 文件中的这段代码不起作用:

- (IBAction)button:(UIButton *)sender {
    [AlertStatus alertStatus:@"" :@"Message1" :0];
    [sender performSegueWithIdentifier:@"segueTo1" sender:sender];
}

我得到一个 “'UIButton' 没有可见的@interface 声明选择器 performSegueWithIdentifier:sender:'” 错误信息

有人可以帮忙吗?我也听说过在主视图中使用委托,但我没有这方面的经验。

【问题讨论】:

    标签: objective-c segue nib


    【解决方案1】:

    这很容易解决。 您必须从视图控制器执行 segue,而不是按钮。

    - (IBAction)button:(UIButton *)sender {
        [AlertStatus alertStatus:@"" :@"Message1" :0];
        [self performSegueWithIdentifier:@"segueTo1" sender:sender];
    }
    

    此代码将起作用

    【讨论】:

    • 我尝试了你所说的。但它仍然不起作用。此代码是放在 NIB .m 文件还是 ViewController .m 文件中?我将编辑顶部以更好地解释。
    • 你必须把它放在 ViewControllers .m 文件中。你应该让你的 ViewController 成为你的按钮的代表,而不是使用 [self performSegueWithIdentifier:@"segueTo1" sender:sender]; 从 ViewController 执行 segue 请记住:只有视图控制器可以执行 segue,而不是视图
    • 感谢您的信息。我将研究代表的按钮点击情况。如果你愿意,一个例子会很棒,对我自己和其他人都有帮助:)
    【解决方案2】:

    我不知道如何使用 segue,但您也可以使用以下代码。如果不需要使用 segue,则可以使用此代码。

    UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main_iPhone" bundle:nil];
    OtherViewController *mvc = [sb instantiateViewControllerWithIdentifier:@"OtherViewController"];        
    [self.navigationController pushViewController:mvc animated:YES];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多