• dismissViewControllerAnimated有延迟


    dismissViewControllerAnimated:completion:在应用中运行正常,就是不知道为什么出现了几秒钟的延迟:

    [api loginWithUsername:[dict objectForKey:@"username"] andPassword:[dict objectForKey:@"password"] andSuccessBlock:^(id json) {
        NSLog(@"DONE... %@", [json objectForKey:@"status"]);
        NSString *status = [json objectForKey:@"status"];
        if([status isEqualToString:@"ok"]){
            app.user = [json objectForKey:@"data"];
            [self dismissViewControllerAnimated:YES completion:nil];
        }else{
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"could not log you in" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
            [alert show];
        }
    }];

    在控制台可以看见DONE... ok。,意味着回调block执行正常,但是接下来需要三四秒钟延迟视图才能最终被dismiss。

    怎么解决这个延迟问题?谢谢

    如果你不能保证UI代码运行在主线程中,它可能就运行到其他地方去了,这样的话会出现几秒钟的延迟。

    添加下面的代码可以让dismissal运行在主线程中:

    dispatch_async(dispatch_get_main_queue(), ^{
        [self dismissViewControllerAnimated:YES completion:nil]
    });
  • 相关阅读:
    个人总结21
    个人总结08
    个人总结07
    构建之法读后感01
    学习进度表 03
    四则运算3
    求最大值
    学习进度表02
    四则运算 2
    学习进度表01
  • 原文地址:https://www.cnblogs.com/lear/p/3957248.html
Copyright © 2020-2023  润新知