【问题标题】:connecting the segue, using the programatically created button使用以编程方式创建的按钮连接 segue
【发布时间】:2014-07-06 06:02:14
【问题描述】:

我已经在 viewdidload 方法中创建了按钮:

    UIButton * button2 = [UIButton buttonWithType:UIButtonTypeCustom];
    [button2 addTarget:self action:@selector(showVideo:)forControlEvents:UIControlEventTouchUpInside];

在按钮操作方法中,我以编程方式调用了 segue:

    - (void) showVideo:(id)sender {
       [self performSegueWithIdentifier: @"MySegue" sender: self];  
     }

在准备 segue 方法中调用模态视图控制器的代码

    - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
    {
        if ([[segue identifier] isEqualToString:@"MySegue"])
          {
            Xen_VideoViewController *addController = [segue destinationViewController];
            [self presentViewController:addController animated:YES completion: nil];
          }
    }

我参考了链接[链接]:Creating a segue programmatically

但我得到的错误是

“应用程序试图以模态方式呈现活动控制器”

我需要在按下按钮时显示模态视图控制器,但按钮是以编程方式创建的。该按钮在滚动视图中重复出现。

还有其他获取模态视图控制器的方法吗?

提前致谢……

【问题讨论】:

    标签: ios objective-c segue


    【解决方案1】:

    您不应该在 prepareForSegue 方法上使用 present addController

    我指的是你自己分享的链接:

    https://stackoverflow.com/a/17012857/1939409

    您应该在您的xib 文件中创建seque,然后在您调用以下行时:

       [self performSegueWithIdentifier: @"MySegue" sender: self];  
    

    应用程序将根据您的 xib 创建的segue 显示目的地ViewController。所以这没有必要在prepareForSegue方法中调用presentViewController

    如果您已经在 xib 中创建了 segue,那么只需删除 prepareForSegue 方法,一切都应该没问题。

    如果你甚至不想在你的 xib 中创建 segue。所以我认为唯一的方法是呈现模态视图控制器。

    【讨论】:

    • 感谢 Husein,它为我工作……再次感谢您为我节省时间……
    • 如何在不使用prepare segue方法的情况下为模态视图控制器传递数据有没有其他方法...
    • 我个人使用的公共属性是modal viewController
    • 只需在 google 中搜索“定义类属性”即可查看示例
    猜你喜欢
    • 2014-12-14
    • 2013-11-08
    • 2012-03-29
    • 1970-01-01
    • 2012-07-24
    • 1970-01-01
    • 2018-06-14
    • 2018-09-10
    • 1970-01-01
    相关资源
    最近更新 更多