现在我有两个视图控制器。我的问题是我不知道如何在更改为第二个视图控制器后隐藏后退按钮。主要是我在Objective-C中找到的参考文献。我如何在swift中编码?
隐藏objective-c
中的按钮代码[self.navigationItem setHidesBackButton:YES animated:YES];
答案 0 :(得分:288)
来自UINavigationItem class reference documentation -
self.navigationItem.setHidesBackButton(true, animated:true);
答案 1 :(得分:29)
如果你正在使用UITabBarController:
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
self.tabBarController?.navigationItem.hidesBackButton = true
}
答案 2 :(得分:13)
Swift
// remove left buttons (in case you added some)
self.navigationItem.leftBarButtonItems = []
// hide the default back buttons
self.navigationItem.hidesBackButton = true
答案 3 :(得分:7)
这也可以在UINavigationController类文档中找到:
navigationItem.hidesBackButton = true
答案 4 :(得分:2)
您可以尝试使用以下代码
override func viewDidAppear(_ animated: Bool) {
self.navigationController?.isNavigationBarHidden = true
}
答案 5 :(得分:1)
self.navigationItem.setHidesBackButton(true, animation: false)
答案 6 :(得分:0)
navigationItem.hidesBackButton = true。放在viewDidLoadMethod
答案 7 :(得分:0)
这是
// MARK: - Hiding Back Button
extension UINavigationItem {
/// A Boolean value that determines whether the back button is hidden.
///
/// When set to `true`, the back button is hidden when this navigation item
/// is the top item. This is true regardless of the value in the
/// `leftItemsSupplementBackButton` property. When set to `false`, the back button
/// is shown if it is still present. (It can be replaced by values in either
/// the `leftBarButtonItem` or `leftBarButtonItems` properties.) The default value is `false`.
@IBInspectable var hideBackButton: Bool {
get { hidesBackButton }
set { hidesBackButton = newValue }
}
}
视图控制器的每个导航项都将在属性检查器的顶部具有此新属性
答案 8 :(得分:0)
在Swift 5中对我来说就像魅力一样, 只需将其添加到您的viewDidLoad()
self.navigationItem.setHidesBackButton(true, animated: true)
答案 9 :(得分:-1)
转到属性检查器,然后取消选中“显示导航栏”以隐藏“后退”按钮。