ios - Reloading a UINavigationItem -


i want load view controller 1 navitem.rightbarbuttonitem , change based on set of circumstances. seems if can load once, on viewdidload. there method updating bar button item after you've changed icon?

func viewdidload() {     var iconone = uiimage(named: "button")     let buttonone = uibarbuttonitem(image: iconone, style: uibarbuttonitemstyle.plain, target: self, action: "funcone")     self.navitem.rightbarbuttonitem = buttonone      //perform async query, if condition holds true then:      var icontwo = uiimage(named: "buttontwo")     let buttontwo = uibarbuttonitem(image: icontwo, style: uibarbuttonitemstyle.plain, target: self, action: "functwo")     self.navitem.rightbarbuttonitem = buttontwo } 

full code:

override func viewdidload() {         super.viewdidload()           // sets custom nav bar view can add multiple bar buttons         navbar = uinavigationbar(frame: cgrectmake(0, 20, uiscreen.mainscreen().bounds.size.width, 44))         navbar.bartintcolor = uicolor.blackcolor() // sets bar black         navbar.translucent = false         self.view.addsubview(navbar)         navitem = uinavigationitem(title: "\(name)") // sets title         navbar.titletextattributes = [ nsfontattributename: uifont(name: "helvetica neue", size: 25)!,  nsforegroundcolorattributename: uicolor.whitecolor()] // set icons             var backicon = uiimage(named: "backbutton")             let backbutton = uibarbuttonitem(image: backicon, style: uibarbuttonitemstyle.plain, target: self, action: "backbutton")             navitem.leftbarbuttonitem = backbutton              var userquery = pfquery(classname: "followers")             userquery.wherekey("following", equalto: username)             userquery.findobjectsinbackgroundwithblock({ (objects, error) -> void in                 if error == nil {                      if let objects = objects {                          object in objects {                              if let follower = object["follower"] as? string {                                 if follower == pfuser.currentuser()!.username! {                                     var followingicon = uiimage(named: "followingbutton")                                     let followingbutton = uibarbuttonitem(image: followingicon, style: uibarbuttonitemstyle.plain, target: self, action: "unfollowuser")                                     self.navitem.rightbarbuttonitem = followingbutton                                      self.navitem.rightbarbuttonitem?.tintcolor = uicolor.orangecolor()                                 } else {                                      var followicon = uiimage(named: "followbutton")                                     let followbutton = uibarbuttonitem(image: followicon, style: uibarbuttonitemstyle.plain, target: self, action: "followuser")                                     self.navitem.rightbarbuttonitem = followbutton                                       self.navitem.rightbarbuttonitem?.tintcolor = uicolor.darkgraycolor()                                 }                             }                         }                      }                 } else {                     println(error)                 }             }) 

i'm not sure if possible. so, made own custom view each bar button item be. set right bar button item @ var rightbutton = uibutton(frame: cgrectmake(uiscreen.mainscreen().bounds.width - 50, 25, 30, 30)), added action, , added subview view.


Comments