最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

[已解决]swift中tableview中modalPresentationStyle为Custom去presentViewController显示另外一个tableview结果第一次加载显示时很慢

iOS crifan 2656浏览 0评论

最终通过调试,看log

2016-07-07 14:34:13.851 [Verbose] [main] [TaskManagementViewController.swift:417] tableView(_:didSelectRowAtIndexPath:) > after self.presentViewController(selectItemVC
2016-07-07 14:34:15.526 [Verbose] [main] [SelectItemViewController.swift:102] tableView(_:cellForRowAtIndexPath:) > tableView=<UITableView: 0x7a250800; frame = (15 152; 290 264); clipsToBounds = YES; gestureRecognizers = <NSArray: 0x79860280>; layer = <CALayer: 0x79775300>; contentOffset: {0, 0}; contentSize: {290, 264}>, indexPath=<NSIndexPath: 0x797b34d0> {length = 2, path = 0 – 0}

而发现代码:

    func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath){
        gLog.verbose(“tableView=\(tableView), indexPath=\(indexPath)”)
。。。
                gLog.verbose(“before let selectItemVC = SelectItemViewController”)
                let selectItemVC = SelectItemViewController(curSelectIdx: self.selectTaskType, selectItemList: items, completionHadler: self.getTeskType(_:))
                gLog.verbose(“selectItemVC=\(selectItemVC)”)
                selectItemVC.modalPresentationStyle = .Custom
//                dispatchMain_async({
                gLog.verbose(“before self.presentViewController(selectItemVC”)
                    self.presentViewController(selectItemVC, animated: true, completion: nil)
//                })
                gLog.verbose(“after self.presentViewController(selectItemVC”)

之后,加载并显示另外一个tableview,第一次会很慢

swift tableview presentViewController another tableiview slow

ios – ViewController presented slowly in didSelectRowAtIndexPath – Stack Overflow

ios – presentViewController:animated:YES view will not appear until user taps again – Stack Overflow

ios – UITableView and presentViewController takes 2 clicks to display – Stack Overflow

ios – Delay in presenting a modal view controller – Stack Overflow

rdar://19563577: Calling presentViewController:animated:completion: from within tableView:didSelectRowAtIndexPath: is very slow

Developer Forums: Very long delay (20 seconds) to bring up modal view in iOS7, instant in iOS 6

[总结]

在tableview中的didSelectRowAtIndexPath去用presentViewController另外一个viewcontroller

由于iOS自己的bug,有时候显示很慢,有时候又很正常的及时显示

没有彻底的解决办法,只有wordkaround:

    dispatch_async(dispatch_get_main_queue()) {
      self.presentViewController(selectItemVC, animated: true, completion: nil)
    }

即可。

转载请注明:在路上 » [已解决]swift中tableview中modalPresentationStyle为Custom去presentViewController显示另外一个tableview结果第一次加载显示时很慢

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
83 queries in 0.276 seconds, using 22.34MB memory