How to check if a view controller can perform a segue

前端 未结 8 1979
长发绾君心
长发绾君心 2020-12-29 02:10

This might be a very simple question but didn\'t yield any results when searching for it so here it is...

I am trying to work out a way to check if a certain view co

相关标签:
8条回答
  • 2020-12-29 02:58

    You can override the -(BOOL)shouldPerformSegueWithIdentifier:sender: method and do your logic there.

    - (BOOL) shouldPerformSegueWithIdentifier:(NSString *)identifier sender:(id)sender {
        if ([identifier isEqualToString:@"someSegue"]) {
            if (!canIPerformSegue) {
                return NO;
            }
        }
        return YES;    
    }
    

    Hope this helps.

    0 讨论(0)
  • 2020-12-29 03:02

    There is no way to check that using the standard functions, what you can do is subclass UIStoryboardSegue and store the information in the source view controller (which is passed to the constructor). In interface builder select "Custom" as the segue type as type the class name of your segue, then your constructor will be called for every segue instantiated and you can query the stored data if it exists.

    You must also override the perform method to call [source presentModalViewController:destination animated:YES] or [source pushViewController:destination animated:YES] depending on what transition type you want.

    0 讨论(0)
提交回复
热议问题