I am developing an ios application using storyboard and swift. I have a small issue with the title near the navigation icon not hiding.I am setting the code like self.navigationController?.navigationItem.backBarButtonItem?.title = ""
But it also not worked. I have attached the screenshot. How to fix this?
This is pretty simple to do. But first a little of theory. The backBarButonItem
does not affect the current ViewController
, it affect the next in the stack of the UINavigationController
. I will give you an example. If you have the ViewController
A
and the ViewController
B
, then to accomplish your task, you set the backBarButtonItem
in A
with a blank space in the title
. Then when you go A -> B
you will see only the arrow in the top left corner.
Exist two way to solve this issue, one in the storyboard
and the other is in code.
storyboard
you need to set like in the next picture the Back Button title with an single space like you can seeFirst put this code anywhere in your project
extension UIViewController {
@IBAction func unwind(_ sender: UIStoryboardSegue)
{
}
}
With that, then in A ViewController
you can do then this:
class ViewControllerA: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
self.navigationItem.backBarButtonItem = UIBarButtonItem(title: " ", style: .plain, target: self, action: #selector(unwind(_:)))
}
}
Good coding. Best regards
Add the below code in your viewDidLoad
method
self.navigationController?.navigationBar.topItem?.title = ""
viewWillAppear
of previous ViewController if you want.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.