【问题标题】:Segue performs even though identifier is not met即使不满足标识符,Segue 也会执行
【发布时间】:2014-07-20 09:51:49
【问题描述】:

我已经使用样式推送创建了一个从 uibutton 到 viewController 的 segue。我只希望在满足条件时推动这个 segue。因此我创建了一个这样的标识符:

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

但是,即使没有调用 performSegueWithIdentifier,segue 似乎也正在被推送。我该如何解决这个问题?

【问题讨论】:

    标签: ios objective-c segue


    【解决方案1】:

    不要让 segue 直接从按钮转到,而是将 UIButton 连接到视图控制器上的 IBAction。然后,在此 IBAction 中,检查您的状况并调用您的 performSegue。当直接从按钮挂钩 segue 时,不会首先咨询 ViewController。

    【讨论】:

    • 那么连接在哪里呢?我需要给某物一个标识符。
    • 就像@codester 在他的回答中所说,它需要添加在两个 ViewController 之间。
    • 您也可以实现shouldPerformSegueWithIdentifier 方法来潜在地否决segue,但我的偏好是根据标准更改按钮的启用状态 - 这会提供按钮处于非活动状态而不是离开的视觉反馈用户想知道为什么什么都没发生
    【解决方案2】:

    从按钮中删除segue 并将其从ViewController 连接到AnotherViewController,因为pushsegue 而不是UIButton

    并检查条件并执行segue

    if(this == that){
    
        [self performSegueWithIdentifier:@"LoginSuccessful1" sender:self];
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-08-07
      • 1970-01-01
      • 2020-12-24
      • 1970-01-01
      • 1970-01-01
      • 2016-03-14
      • 1970-01-01
      相关资源
      最近更新 更多