navigationBar.isHidden 和 setNavigationBarHidden 之间的区别 [英] difference between navigationBar.isHidden and setNavigationBarHidden
问题描述
我有视图控制器,我从隐藏导航栏的视图控制器推送它.但我想在目标视图控制器中显示导航栏.
I have view controller which I am pushing from a view controller where navigation bar is hidden. But I want to show the navigation bar in destination view controller.
我用这个语句尝试过它没有显示导航栏.
I tried with this statement it was not showing navigationBar.
self.navigationController?.navigationBar.isHidden = false
我试过这个声明它正在工作
I tried this statement it is working
self.navigationController?.setNavigationBarHidden(false, animated: true)
我想知道有什么区别?
推荐答案
不,它们不一样,
self.navigationController?.isNavigationBarHidden
是一个 getter 属性(它会显示导航栏是否隐藏.)它只会返回一个布尔值,传达导航栏天气的状态是否隐藏.(尝试将其值分配给 bool 就像 var isHidden = self.navigationController?.isNavigationBarHidden
它会根据 NavBar 的状态为您提供 true 或 false.)
is a getter property (it shows you wheather the navBar is hidden or not.) It will just return a boolean value conveying the state of the NavBar weather it is hidden or not.
(try assigning its value to bool like var isHidden = self.navigationController?.isNavigationBarHidden
it will give you true of false according to state to the NavBar.)
而self.navigationController?.setNavigationBarHidden(false, animation: true)
是一个 setter 属性,它为您提供设置导航栏的状态.
is a setter propety which gives you the provision of setting the state of the navBar.
编译器不会在 self.navigationController?.isNavigationBarHidden = false 上抛出任何错误
但不会做任何事情,因为您只能从这里了解状态.
Compiler does not throw any error on self.navigationController?.isNavigationBarHidden = false
but will not do anything as you can only know the state from here.
这篇关于navigationBar.isHidden 和 setNavigationBarHidden 之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!