【发布时间】:2017-06-28 22:22:45
【问题描述】:
好的,我查看了 performSegueWithIdentifier very slow when segue is modal 并尝试了类似的解决方案,但我仍然遇到问题 - 我在 Swift 工作,并且基于来自列表 VC 单元的点击执行 segue 需要 5-30秒。它只是挂在那里并选择了条。
我尝试用
加快速度DispatchQueue.main.async {
self.performSegue(withIdentifier: "toPodcastPlayer", sender: self)
}
然而,这一切并没有使栏选择颜色。如果发生这种情况,我需要显示一个加载屏幕,但是当使用这个函数进行加载时:
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 类型是现在的模态,没有被弃用。
【问题讨论】:
-
您是否尝试过在 Instruments 中对其进行概要分析以查看需要这么长时间的原因?你对
didSelectRowAtIndexPath()的调用已经在主线程上,不应该是异步调用,所以你不需要在这里使用GCD。设置这些属性时,PodcastViewController中发生了什么? -
一旦你调用了
performSegue,segue 就基本上被提交了(你可以通过从shouldPerformSegue返回false来中止它)。如果您需要显示加载 UI,您应该在目标视图控制器中执行此操作。您还需要确保在后台线程上异步执行任何加载。加载完成后,您将移除加载 UI 并显示加载的数据。 -
我的问题是无论我在目的地做什么,“加载”时间延迟都会发生在列表VC上,然后在目的地有点。如果我尝试像我在列表视图中所说的那样显示加载,它不会显示它,直到 segue 开始实际工作
-
@CraigOtis 播客视图开始流式传输 m4a 并在视图中播放它确实加载了,一旦 segue 进入低谷,这需要一点时间,但我不明白为什么有些加载会甚至在它出现之前发生在选定的视图上。即使我希望它在到达目的地时播放,我是否应该延迟目的地中的播放功能?
标签: ios swift segue loading uistoryboardsegue