I have navigationItem initialized in viewDidLoad() method, like below:
navigationItem.leftControls = [menuButton]
navigationItem.rightControls = [searchButton]
But I want to remove all controls in leftControls and rightControls when a button clicked:
navigationItem.leftControls = nil
navigationItem.rightControls = [filterButton]
And all button still remain...
How can I resolve this problem? Thanks.
@nthtrung09it try
`navigationitem.leftControls.first.removeFromSuperView()
or maybe a loop to remove all using tags :)
@chashmeetsingh Thanks for your quick response!
I hope it helped 馃憤
Thanks @chashmeetsingh
For anyone else that might run into this issue, I found that when I wanted to replace an existing item with another one I had to call layoutSubviews() on the navigationBar to get the controls to update properly.
navigationItem.rightControls.first.removeFromSuperview()
navigationItem.rightControls = [newControl]
navigationController?.navigationBar.layoutSubviews()
Most helpful comment
For anyone else that might run into this issue, I found that when I wanted to replace an existing item with another one I had to call layoutSubviews() on the navigationBar to get the controls to update properly.
navigationItem.rightControls.first.removeFromSuperview()
navigationItem.rightControls = [newControl]
navigationController?.navigationBar.layoutSubviews()