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?

有帮助吗?

解决方案

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.

其他提示

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

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

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top