ios - 当某些情况发生时如何停止插入segue?

标签 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];

    }

}

谢谢

最佳答案

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

}

}

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

相关文章:

ios - 从 NSManagedObject 获取类型

iphone - 在 Objective-c 中截断字符串并在末尾添加省略号

ios - 如何将 2 个 NSDictionary Contain 数组合并到一个 NSMutableArray

objective-c - 哪个持久内存是更好的选择?

ios - 如何以编程方式创建 segue 以在 View Controller 之间传递信息 - Swift

ios - 集成 Nuance Dragon Mobile 时架构 x86_64 的 undefined symbol

ios - UITextView 中不需要的滚动空间

objective-c - iOS 5 - 关机 Hook

ios - 如果我显示 destinationViewController,自定义 Fade Segue 不会设置动画

ios - 通过没有 Storyboard的函数从另一个类执行 Segue