Delay in presenting a modal view controller

前端 未结 9 1732
星月不相逢
星月不相逢 2020-12-24 10:51

I have a tab bar based app. There are navigation controllers in all 5 tabs with instances of custom view controller setup properly as root view controllers. This loads just

相关标签:
9条回答
  • 2020-12-24 11:25

    I have also had this strange delay when presenting from tableView:didSelectRowAtIndexPath: looks like an Apple bug.

    This solution seems to work well though.

    CFRunLoopWakeUp(CFRunLoopGetCurrent()); // Fixes a bug where the main thread may be asleep, especially when using UITableViewCellSelectionStyleNone
    
    0 讨论(0)
  • 2020-12-24 11:29

    It seems calling presentViewController:animated:completion from within tableView:didSelectRowAtIndexPath: is problematic. It's difficult to find anything that stands out when using the Time Profiler in Instruments, also. Sometimes my modal view comes up in less than a second and other times it takes 4s or even 9s.

    I think it's related to the underlying UIPresentationController and layout, which is one of the few things I see when selecting the region of time between tapping on a row and seeing the modal presentation in the Time Profiler.

    A Radar exists describing this issue: http://openradar.appspot.com/19563577

    The workaround is simple but unsatisfying: delay the presentation slightly to avoid whatever contentious behavior is causing the slowdown.

    dispatch_async(dispatch_get_main_queue(), ^{
       [self presentViewController:nav animated:YES completion:nil];
    });
    
    0 讨论(0)
  • 2020-12-24 11:30

    The common problem with this behaviour is as follows:

    one sets selectionStyle = .none for a cell in the tableView (it seems that it doesn't depend on UITableViewController subclassing as was written at http://openradar.appspot.com/19563577) and uses at the delegate method

    override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)
    

    animating deselect

    tableView.deselectRow(at: indexPath, animated: true)
    

    which implies animation for non-animating cell.

    In this case the subsequent view controller presentation has a delay.

    There are some workaround solutions including dispatch_async on main thread, but it is better not to call deselectRow even without animation on unselectable cells in your code.

    0 讨论(0)
提交回复
热议问题