OGeek|极客世界-中国程序员成长平台

标题: ios - 发生某些情况时如何停止插入segue? [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 18:14
标题: ios - 发生某些情况时如何停止插入segue?

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

-(void)prepareForSegueUIStoryboardSegue *)segue senderid)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];

    }

}

谢谢



Best Answer-推荐答案


- (BOOL)shouldPerformSegueWithIdentifierNSString *)identifier sendernullable id)sender NS_AVAILABLE_IOS(6_0);

你可以重写这个方法,当某些情况发生时,返回 No 停止执行 segue。

例如

- (BOOL)shouldPerformSegueWithIdentifierNSString *)identifier senderid)sender {



    if ([identifier isEqualToString"showShoping" ]) {



        return NO;

  }
 return YES;

}

}

关于ios - 发生某些情况时如何停止插入segue?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34893421/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4