当某些情况发生时,如何停止推送segue?

时间:2016-01-20 06:58:15

标签: ios objective-c segue

如何在某些条件失败时停止推送segue

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{

    internet *myclass = [[internet alloc]init];
    if ([myclass connectedToInternet]) {


    if ([[segue identifier] isEqualToString:@"showShoping"]) {
        _pass = @"shop";
        MyTabController *mvc = (MyTabController *)segue.destinationViewController;
        mvc.myCategory = _pass;
    }
    if ([[segue identifier] isEqualToString:@"showTravel"]) {
        _pass = @"travel";
        MyTabController *mvc = (MyTabController *)segue.destinationViewController;
        mvc.myCategory = _pass;
    }
    if ([[segue identifier] isEqualToString:@"showFood"]) {
        _pass = @"food";
        MyTabController *mvc = (MyTabController *)segue.destinationViewController;
        mvc.myCategory = _pass;
    }
    else{

        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"No Internet!"
                                                        message:@"No working internet connection is found."
                                                       delegate:nil
                                              cancelButtonTitle:@"OK"
                                              otherButtonTitles:nil];
        [alert show];

    }

}

谢谢

1 个答案:

答案 0 :(得分:2)

- (BOOL)shouldPerformSegueWithIdentifier:(NSString *)identifier sender:(nullable id)sender NS_AVAILABLE_IOS(6_0);

您可以覆盖此方法,返回No以在某些情况发生时停止执行segue。

例如

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



    if ([identifier isEqualToString:@"showShoping" ]) {



        return NO;

  }
 return YES;

}

}