Navigation bar topitem add right bar button item not shown iOS swift

 Problem:

I want to add condition that sometime right bar button item shown and sometime it will not to be shown.That condition all time no button came.But i added item.My code as like below.

        if i == 0 {

            self.navBar.topItem?.rightBarButtonItems = [saveButton]

        } 


Solution:

The above code have a problem that you cannot initialise and assigned right bar button item.First you have to assign right bar button item and then add it.It will works.Change the code as like below.

        self.navBar.topItem?.rightBarButtonItems = []

        if i == 0 {

            self.navBar.topItem?.rightBarButtonItems = [saveButton]

        } 


Comments

Popular posts from this blog

Invalid bundle error while upload the app to the app Store

Convert NsNumber, NSDate to String in iOS Swift

Global LocationManager Singleton class iOS Swift