从另一个视图控制器返回后如何为主故事板保留大标题?
How to keep large title on for main storyboard after going back from another view controller?
我正在尝试在我的主页和另一个情节提要板上使用具有不同 preferlargetitles
布尔值的导航控制器。当我开始模拟时,它会登陆带有大标题 true
的主页。然后我点击一个 collection 视图单元格来查看 pdf,并且我将该视图控制器的大标题设置为 false(或者我相信)。当我按导航控制器上的后退按钮返回主页时,大标题现在设置为 false。
我曾尝试在 collectionview
viewDidLoad
中将大标题设置为 true 但没有成功。
转到 pdf 视图控制器的主页代码:
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let selectedRow = indexPath.row
if selectedRow == 0 {
print("add button selected")
return
}
else {
let document = Data.documentModel[selectedRow - 1]
let storyboard = UIStoryboard(name: String(describing: NoteTakingViewController.self), bundle: nil)
let vc = storyboard.instantiateInitialViewController() as! NoteTakingViewController
vc.document = document
//self.present(vc, animated: true, completion: nil)
self.show(vc, sender: selectedRow)
}
从主页点击文件后 pdf 视图控制器内部的代码:
override func viewDidLoad() {
super.viewDidLoad()
....(to view the pdf code went here)
self.title = document.title
navigationController?.navigationBar.prefersLargeTitles = false
// Do any additional setup after loading the view.
}
当我转到故事板时,我得到了小标题,但它会转到主页。
在你的主视图控制器中写下这行代码,这样当你来到这个视图控制器时,标题将被设置为大,现在你可以从viewdidLoad中移除
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated) // No need for semicolon
navigationController?.navigationBar.prefersLargeTitles = true
}
在情节提要的导航栏中,未选中“首选大标题”。
在您必须使用大标题的视图控制器中:
self.navigationController?.navigationBar.prefersLargeTitles = true
我正在尝试在我的主页和另一个情节提要板上使用具有不同 preferlargetitles
布尔值的导航控制器。当我开始模拟时,它会登陆带有大标题 true
的主页。然后我点击一个 collection 视图单元格来查看 pdf,并且我将该视图控制器的大标题设置为 false(或者我相信)。当我按导航控制器上的后退按钮返回主页时,大标题现在设置为 false。
我曾尝试在 collectionview
viewDidLoad
中将大标题设置为 true 但没有成功。
转到 pdf 视图控制器的主页代码:
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let selectedRow = indexPath.row
if selectedRow == 0 {
print("add button selected")
return
}
else {
let document = Data.documentModel[selectedRow - 1]
let storyboard = UIStoryboard(name: String(describing: NoteTakingViewController.self), bundle: nil)
let vc = storyboard.instantiateInitialViewController() as! NoteTakingViewController
vc.document = document
//self.present(vc, animated: true, completion: nil)
self.show(vc, sender: selectedRow)
}
从主页点击文件后 pdf 视图控制器内部的代码:
override func viewDidLoad() {
super.viewDidLoad()
....(to view the pdf code went here)
self.title = document.title
navigationController?.navigationBar.prefersLargeTitles = false
// Do any additional setup after loading the view.
}
当我转到故事板时,我得到了小标题,但它会转到主页。
在你的主视图控制器中写下这行代码,这样当你来到这个视图控制器时,标题将被设置为大,现在你可以从viewdidLoad中移除
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated) // No need for semicolon
navigationController?.navigationBar.prefersLargeTitles = true
}
在情节提要的导航栏中,未选中“首选大标题”。
在您必须使用大标题的视图控制器中:
self.navigationController?.navigationBar.prefersLargeTitles = true