我在父视图控制器中有一个按钮(searchButton)。按钮(searchButtonTapped)的操作是锁定到Result View Controller,如下所示。
@IBAction func searchButtonTapped(_ sender: Any) {
let mainStoryboard = UIStoryboard(name: "SearchResult", bundle: Bundle.main)
guard let resultViewController = mainStoryboard.instantiateViewController(withIdentifier: "ResultViewController") as? ResultViewController else { return }
resultViewController.resultText = initialText
navigationController?.pushViewController(resultViewController, animated: true)
}
当我第一次点击按钮(searchButton)时,segue动作发生了,但有2秒的延迟。当我回到父视图控制器并再次点击按钮时,从第二次开始,提示就很流畅了。启动该应用程序后,只有第一个segue有两秒钟的延迟。我在这里耽误了什么错?您的想法将不胜感激。谢谢。
这是子视图控制器(ResultViewController)的viewDidLoad。我尝试将“ A”打印到“ F”,以便确定导致延迟的步骤,但是,当我点击searchButton时,所有从A到F的打印都不会延迟。然后,在打印“ F”之后,它会延迟约2秒钟,然后屏幕才能使用推送功能进行更新。
override func viewDidLoad() {
super.viewDidLoad()
print("A")
populateDataArray(resultText.isEmpty)
resetSelectedItemArray(movingIn: true)
print("B")
headerView = listTableView.tableHeaderView as? ResultTableHeaderView
headerView.bannerImageView.contentMode = .scaleAspectFill
listTableView.tableHeaderView = nil
listTableView.addSubview(headerView)
listTableView.contentInset = UIEdgeInsets(top: tableHeaderViewHeight, left: 0, bottom: 0, right: 0)
print("C")
initializeHeaderView()
setupRightBarButtonItems()
setupInformationBar()
setupTableViewStyle()
print("D")
navigationItem.setHidesBackButton(true, animated: false)
let layout: UICollectionViewFlowLayout = UICollectionViewFlowLayout()
layout.minimumInteritemSpacing = 5
layout.scrollDirection = .horizontal
resultCollectionView.collectionViewLayout = layout
print("E")
resultCollectionView.delegate = self
resultCollectionView.dataSource = self
listTableView.delegate = self
listTableView.dataSource = self
stickyDropDownTableView.delegate = self
stickyDropDownTableView.dataSource = self
informationDropDownTableView.delegate = self
informationDropDownTableView.dataSource = self
print("F")
}
答案 0 :(得分:0)
通常,当目标视图特别复杂并且肯定需要任何繁重的处理才能加载时,就会发生这种情况,并且需要花费一些时间。但是你的看起来不像。因此,您可以在主线程内执行segue,这可以缓解问题。
DispatchQueue.main.async {
navigationController?.pushViewController(resultViewController, animated: true)
}