2012-01-24 24 views
12

根据XML返回,我不希望当前segue在UIButton touch上执行。ios segue“取消”

我知道我可以选择我想要的segue执行,但如何使一个segue执行?或至少不执行任何可用的segues

回答

25

如果您的部署目标是iOS 6.0以上版本,您可以覆盖the -[UIViewController shouldPerformSegueWithIdentifier:sender:] method返回YES,如果你想,如果你不执行SEGUE和NO

如果您的部署目标早于iOS 6.0,您将不会收到shouldPerformSegueWithIdentifier:sender:消息。所以在你的故事板中,不要从按钮上画出轮廓。相反,从按钮的视图控制器中绘制segue并给segue一个标识符。将按钮连接到其视图控制器中的IBAction。在操作中,检查您是否要执行搜寻。如果你想要执行它,发送你自己performSegueWithIdentifier:sender:,将你分配给segue的标识符传给故事板。

+0

是' [self performSegueWithIdentifier:@“myIdentifier”sender:self];'correct? Xcode给了我一个'SIGABRT' :( – Jacksonkr

+0

)你需要设置一个异常断点来看看发生了什么问题 –

3

Apple Developer Documentation有正确的方法取消一个故事板内管理的赛格瑞:

- (BOOL)shouldPerformSegueWithIdentifier:(NSString *)identifier sender:(id)sender 

例如:

- (BOOL)shouldPerformSegueWithIdentifier:(NSString *)identifier sender:(id)sender { 
    if ([identifier isEqualToString:@"listPopover"]) { 
     if (self.listPopover == nil) { 
      // Allow the popover segue 
      return YES; 
     } 
     // Cancel the popover segue 
     return NO; 
    } 
    // Allow all other segues 
    return YES; 
} 
+0

'shouldPerformSegueWithIdentifier:sender:'消息是在iOS 6中添加的,不会在运行早期版本iOS的设备上发送。当这个问题发布后,iOS 6还没有发布。 –