[英]Navigation bar title updates too late (Swift)
我有一個tableViewController,顯示了選擇了顯示某些類別的collectionViewController的單元之后(都在navigationViewController內)。 我希望導航欄顯示所選類別的標題,但標題不會及時更新。
這意味着每當我返回並選擇其他類別時,它就會顯示舊標題,即標題始終滯后於視圖?
這是我在collectionViewController中的代碼:
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if (segue.identifier == "CategorySelected") {
let vc = segue.destination as! SearchOrgTableViewController
vc.category = selectedCategory
}
}
並在TableViewController中:
var category: CategoryModel?{
didSet{
guard let name = category?.name else{
return
}
self.navigationItem.title = name
}
}
任何想法如何解決?
我試圖直接在prepare函數中設置標題,結果相同,調用reloadInputViews()也不起作用。
試試這個代碼:
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if (segue.identifier == "CategorySelected") {
DispatchQueue.main.async {
let vc = segue.destination as! SearchOrgTableViewController
vc.category = selectedCategory
vc.title = category.name } }
}
在iOS 10中,UIKit更新並統一了UINavigationBar,UITabBar和UIToolbar的后台管理。 特別是,對這些視圖的背景屬性(例如背景或陰影圖像,或設置欄樣式)的更改可能會啟動欄的布局傳遞,以解決新的背景外觀。 特別是,這意味着嘗試更改-[UIView layoutSubviews],-[UIView updateConstraints],-[UIViewController willLayoutSubviews],-[UIViewController didLayoutSubviews],-[UIViewController updateViewConstraints]或任何其他內部的這些條的背景外觀響應布局而調用的方法可能會導致布局循環。
因此,將發生這種情況。嘗試在加載視圖或顯示視圖時更新標題,可能會對您有所幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.