Material: How to remove leftControls and rightControls after added in NavigationItem

Created on 19 Jul 2016  路  5Comments  路  Source: CosmicMind/Material

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.

help wanted

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()

All 5 comments

@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()

Was this page helpful?
0 / 5 - 0 ratings