ios segue “cancel”

回眸只為那壹抹淺笑 提交于 2019-12-06 19:09:23

问题


Depending on an XML return, I don't want the current segue to perform on UIButton touch.

I know I can pick which segue I want to perform, but how to I make a segue not perform? Or at least not perform any of the available segues?


回答1:


If your deployment target is iOS 6.0 or later, you can override the -[UIViewController shouldPerformSegueWithIdentifier:sender:] method to return YES if you want to perform the segue and NO if you don't.

If your deployment target is earlier than iOS 6.0, you won't receive the shouldPerformSegueWithIdentifier:sender: message. So in your storyboard, don't draw the segue from the button. Instead, draw the segue from the button's view controller and give the segue an identifier. Connect the button to an IBAction in its view controller. In the action, check whether you want to perform the segue. If you want to perform it, send yourself performSegueWithIdentifier:sender:, passing the identifier you assigned to the segue in the storyboard.




回答2:


Apple Developer Documentation has the correct method to cancel a segue that is managed within the StoryBoard:

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

For example:

- (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;
}



回答3:


Check out this thread: https://stackoverflow.com/a/42161944/4791032

You can just check it in func tableView(_ tableView: UITableView, willSelectRowAt indexPath: IndexPath)



来源:https://stackoverflow.com/questions/8993341/ios-segue-cancel

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!