【发布时间】:2020-07-24 01:33:13
【问题描述】:
我在父视图控制器中有一个按钮 (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 是平滑的。仅在应用程序启动后的第一个 segue 有两秒钟的延迟。我做错了什么在这里延迟?您的想法将不胜感激。谢谢。
这是子视图控制器 (ResultViewController) 的 viewDidLoad。我试图将“A”打印到“F”以识别导致延迟的步骤,但只要我点击 searchButton,从 A 到 F 的所有内容都会立即打印。然后在打印“F”之后,它会延迟大约 2 秒,然后屏幕才会使用 push segue 更新。
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")
}
【问题讨论】: