1.presentViewController:animated:completion:显示延迟

现象

在A页面的tableView的回调方法中使用present方法展示下一级viewController:B,出现延迟,断点后了解到,点击后顺序执行了presentViewController方法,但是completion没有紧跟着跳进,B也没有被present出来,而且在当前页面A的等待时间跟在点击A中该Cell前停留在此A页面的时间呈正相关,即点击前停留的越久,present出B页面就需要等越长的时间,如果进入A后直接点击Cell进入B,大概需要等不到1s;稍等3s后,需要等待5s以上。

原因

原因未知,可能是因为present方法不是在主线程中执行的

解决方法

把相关方法放在主线程中执行
原代码:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString* identifier = [_menuArray objectAtIndex:indexPath.row];
    if (identifierRecordManager == identifier) {
        UIViewController *vc = [[HHRecordManagerViewController alloc] initWithModulatorInfo:_info];
        UINavigationController *nv = [[UINavigationController alloc] initWithRootViewController:vc];
        [self presentViewController:nv animated:YES completion:nil];
    }
}

放在主线程调用

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString* identifier = [_menuArray objectAtIndex:indexPath.row];
    if (identifierRecordManager == identifier) {
        dispatch_async(dispatch_get_main_queue(), ^{
            //present方式呈现,会出现界面延迟弹出的问题,放在主线程中可以解决这个问题
            UIViewController *vc = [[HHRecordManagerViewController alloc] initWithModulatorInfo:_info];
            UINavigationController *nv = [[UINavigationController alloc] initWithRootViewController:vc];
            [self presentViewController:nv animated:YES completion:nil];
        });
    }
}

缺点

根本原因未知,治标不治本

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • *面试心声:其实这些题本人都没怎么背,但是在上海 两周半 面了大约10家 收到差不多3个offer,总结起来就是把...
    Dove_iOS阅读 27,216评论 30 472
  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 173,477评论 25 708
  • 发现 关注 消息 iOS 第三方库、插件、知名博客总结 作者大灰狼的小绵羊哥哥关注 2017.06.26 09:4...
    肇东周阅读 12,251评论 4 61
  • 心情有些郁闷,不想找人倾诉,就想涂涂画画,不要想太多。晚安!
    四丫xmh阅读 429评论 2 5
  • 柳宿z阅读 364评论 0 1