Swift - How to hide back button in navigation item

2019-01-13 06:57发布

Right now I have two view controllers. My problem is I don't know how to hide back button after change into second view controller. Mostly references that I found in objective-C. How I code it in swift?

Hide back button code in objective-c

[self.navigationItem setHidesBackButton:YES animated:YES];

标签: ios swift xcode6
6条回答
再贱就再见
2楼-- · 2019-01-13 07:23

enter image description here

Go to attributes inspector and uncheck show Navigation Bar to hide back button.

查看更多
可以哭但决不认输i
3楼-- · 2019-01-13 07:28

In case you're using a UITabBarController:

override func viewWillAppear(animated: Bool) {
    super.viewWillAppear(animated)
    self.tabBarController?.navigationItem.hidesBackButton = true
}
查看更多
狗以群分
4楼-- · 2019-01-13 07:37

You may try with the below code

override func viewDidAppear(_ animated: Bool) {
    self.navigationController?.isNavigationBarHidden = true
}
查看更多
看我几分像从前
5楼-- · 2019-01-13 07:39

Swift

// remove left buttons (in case you added some)
 self.navigationItem.leftBarButtonItems = []
// hide the default back buttons
 self.navigationItem.hidesBackButton = true
查看更多
劫难
6楼-- · 2019-01-13 07:41

This is also found in the UINavigationController class documentation:

navigationItem.hidesBackButton = true
查看更多
太酷不给撩
7楼-- · 2019-01-13 07:44

From the UINavigationItem class reference documentation -

self.navigationItem.setHidesBackButton(true, animated:true);
查看更多
登录 后发表回答