【发布时间】:2012-02-18 02:00:47
【问题描述】:
根据 XML 返回,我不希望当前的 segue 在 UIButton 触摸上执行。
我知道我可以选择我想要执行的segue,但是我如何让segue不执行呢?或者至少不执行任何可用的segues?
【问题讨论】:
根据 XML 返回,我不希望当前的 segue 在 UIButton 触摸上执行。
我知道我可以选择我想要执行的segue,但是我如何让segue不执行呢?或者至少不执行任何可用的segues?
【问题讨论】:
看看这个帖子:https://stackoverflow.com/a/42161944/4791032
你可以在func tableView(_ tableView: UITableView, willSelectRowAt indexPath: IndexPath)查看它
【讨论】:
如果您的部署目标是 iOS 6.0 或更高版本,您可以覆盖 the -[UIViewController shouldPerformSegueWithIdentifier:sender:] method 以在要执行 segue 时返回 YES 或在不执行时返回 NO。
如果您的部署目标早于 iOS 6.0,您将不会收到 shouldPerformSegueWithIdentifier:sender: 消息。所以在你的故事板中,不要从按钮中画出segue。相反,从按钮的视图控制器中绘制 segue 并给 segue 一个标识符。将按钮连接到其视图控制器中的IBAction。在动作中,检查是否要执行转场。如果您想执行它,请给自己发送performSegueWithIdentifier:sender:,将您分配给情节提要中的 segue 的标识符传递给自己。
【讨论】:
[self performSegueWithIdentifier:@"myIdentifier" sender:self]; 正确吗? Xcode 给了我一个SIGABRT :(
Apple Developer Documentation 有正确的方法来取消在 StoryBoard 中管理的 segue:
- (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;
}
【讨论】:
shouldPerformSegueWithIdentifier:sender: 消息是在 iOS 6 中添加的,不会在运行早期版本 iOS 的设备上发送。发布此问题时,iOS 6 尚未发布。