【问题标题】:How to conditionally fire segue based on block-based network operation in iOS?如何在iOS中基于基于块的网络操作有条件地触发segue?
【发布时间】:2014-02-24 16:53:17
【问题描述】:

我有一个基于块的网络功能,我希望只允许 segue 在它成功时开始。这是身份验证的尝试:

[user signUpInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
    NSLog(@"in process");     
    if (!error) {
            NSLog(@"succcess");

        }else{
            NSLog(@"failure");
         }
    }];

如何在 viewController 中使用此语句有条件地开始 segue?

【问题讨论】:

    标签: ios objective-c storyboard segue uistoryboardsegue


    【解决方案1】:

    如果我正确理解了这个问题,[self performSegueWithIdentifier@"YourSegueIdentifierThatYouSetInStoryboard"]; 应该可以解决问题。

    编辑 1:

    要在主线程上触发此代码,请像这样包装您的代码:

    dispatch_async(dispatch_get_main_queue(), ^{ 
        [self performSegueWithIdentifier@"YourSegueIdentifierThatYouSetInStoryboard"]; 
    });
    

    【讨论】:

    • @Atma 是的,没错。因此,如果您不确定完成块是否在主队列上运行,请将 performSegueWithIdentifier 分派到主队列。
    猜你喜欢
    • 1970-01-01
    • 2010-09-26
    • 2023-03-03
    • 2017-08-14
    • 1970-01-01
    • 1970-01-01
    • 2020-05-19
    • 1970-01-01
    • 2016-11-02
    相关资源
    最近更新 更多