XiaoKL

iOS.Performance-trick-presentViewController-is-so-slow-in-didSelectRowAtIndexPath

presentViewController is so slow in "tableView:didSelectRowAtIndexPath:"

 

Use Case: 在UITableView的delegate方法"tableView:didSelectRowAtIndexPath:"中调用

"[UIViewController presentViewController]"发现被显示的ViewController要有很长的延迟

才会显示出来。 

修改后:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    NSInteger rowInSection = indexPath.row;
    switch (rowInSection) {
        case 2: // age
        {
            dispatch_async(dispatch_get_main_queue(), ^{
                NSDate * nowDate = [NSDate date];
                QZDatePickerViewController * datePickerViewController = [[QZDatePickerViewController alloc] initWithDate:nowDate];
                datePickerViewController.delegate = self;
                [self presentViewController:datePickerViewController
                                   animated:NO
                                 completion:nil];
            });

        }
            break;
   }

 

 


Reference 

1. presentViewController:animated:YES view will not appear until user taps again

http://stackoverflow.com/questions/21075540/presentviewcontrolleranimatedyes-view-will-not-appear-until-user-taps-again

posted on 2015-10-23 16:53  XiaoKL  阅读(748)  评论(0编辑  收藏  举报

导航