如何在执行segue之前显示加载指示器?

时间:2017-06-28 22:22:45

标签: ios swift segue loading uistoryboardsegue

好的,我查看了performSegueWithIdentifier very slow when segue is modal并尝试了类似的解决方案,但我仍然遇到问题 - 我在Swift工作,并根据列表中的点击执行segue VC单元格需要好5-30秒。它只是挂在那里,选择了酒吧。

我尝试用

加快速度
DispatchQueue.main.async {
self.performSegue(withIdentifier: "toPodcastPlayer", sender: self)
}

然而,所有这一切并没有让酒吧选择一种颜色。如果要发生这种情况,我需要显示加载屏幕,但是当使用此func进行加载时:

let loadView = UIView(frame: CGRect(x: 0, y: 0, width: 300, height: 300))
       loadView.backgroundColor = UIColor.green
        loadView.center = CGPoint(x: screenSize.width/2, y: screenSize.height/2)
        view.addSubview(loadView)

点击时这个:

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

        let selectedIndexPath : [IndexPath] = self.myTableView.indexPathsForSelectedRows!



     if(self.rssListToLoad[selectedIndexPath[0].row].link != "")
       {
        showLoading()
        self.performSegue(withIdentifier: "toPodcastPlayer", sender: self)
        }

if segue.identifier == "toPodcastPlayer" {
            // find index path for selected row
            let selectedIndexPath : [IndexPath] = self.myTableView.indexPathsForSelectedRows!

            // deselect the selected row
            self.myTableView.deselectRow(at: selectedIndexPath[0], animated: true)

            // create destination view controller
            let destVc = segue.destination as! PodcastViewController

            // set title for next screen
            destVc.adTxtName = "Skylar's Ad"
            destVc.urlStr = self.rssRecordList[selectedIndexPath[0].row].link
            destVc.trackLabel = self.rssRecordList[selectedIndexPath[0].row].title

它仍然延迟。我不明白这一点,因为视图已经在storyboard中创建,只需要在下一个VC中设置一些变量。这有什么不对?

我的segue类型是模态的礼物,而不是弃用。

1 个答案:

答案 0 :(得分:0)

在阅读了你的问题后,我在上一个应用程序中遇到了同样的问题,在尝试了很多解决方案之后我才知道这是Apple的一个漏洞,你可以在这里查看更多信息:http://openradar.appspot.com/19563577

注意:请在主线程上执行segue,它将解决出现控制器的“延迟”问题。

这是执行此操作的代码:

    let vc =  controller as! ViewController

    vc.modalPresentationStyle = .custom

    DispatchQueue.main.async {
         self.present(vc, animated: false, completion: nil)
    }
相关问题