swift - UINavigationController acting funny after pushViewController UPDATE 2 -


i'm having weird problem, have slide menu in app, unknown reason every time go 1 view using .pushviewcontroller instruction navigation controller acts funny , resets uibarbuttonitems. (they change original tintcolor, , badgevalue disappears).

this methods i'm using in slide menu transition:

func openviewcontrollerbasedonidentifier(_ stridentifier:string){     let destviewcontroller : uiviewcontroller = self.storyboard!.instantiateviewcontroller(withidentifier: stridentifier)       let topviewcontroller : uiviewcontroller = self.navigationcontroller!.topviewcontroller!      if (topviewcontroller.restorationidentifier! == destviewcontroller.restorationidentifier!){         print("same vc")     } else {         var numeroproductos = string(carrito.numprod)          self.navigationcontroller!.pushviewcontroller(destviewcontroller, animated: true)       } } 

and

func slidemenuitemselectedatindex(_ index: int32) {     let topviewcontroller: uiviewcontroller = self.navigationcontroller!.topviewcontroller!     print("view controller : \(topviewcontroller) \n", terminator: "")     switch(index) {     case 0:         print("home\n", terminator: "")          self.openviewcontrollerbasedonidentifier("home")          break      case 1:         print("play\n", terminator: "")          self.openviewcontrollerbasedonidentifier("micuenta")          break      case 2:         print("play\n", terminator: "")          self.openviewcontrollerbasedonidentifier("quienessomos")          break      case 3:         print("play\n", terminator: "")          self.openviewcontrollerbasedonidentifier("nuestracausa")          break      case 4:         print("play\n", terminator: "")          self.openviewcontrollerbasedonidentifier("contacto")          break      case 5:         print("play\n", terminator: "")          self.openviewcontrollerbasedonidentifier("faq")          break      default:         print("default\n", terminator: "")     } } 

according apple's own documentation:

a uinavigationitem object manages buttons , views displayed in uinavigationbar object. when building navigation interface, each view controller pushed onto navigation stack must have uinavigationitem object contains buttons , views wants displayed in navigation bar. managing uinavigationcontroller object uses navigation items of topmost 2 view controllers populate navigation bar content.

but not happening, button there in interfase builder , works when land on view without using slide menu, disappears when click option of slide menu.

enter image description here

this code have on viewdidload method on view

override func viewdidload() {     super.viewdidload()     addslidemenubutton()     carrito.numprod = productoscarrito.count     print(productoscarrito.count)     var numeroproductos = string(carrito.numprod)     navigationitem.rightbarbuttonitem?.badgevalue = numeroproductos  } 

if reach page without using slidemenu (like when segue there after succesfully clearing login view) badgevalue shown properly

enter image description here

but if use slide menu happens

enter image description here

any ideas on causing issue?

update

i discovered something.

if insert instruction either in openviewcontrollerbasedonidentifier method or in slidemenuselectedatindex

navigationitem.rightbarbuttonitem?.badgevalue = "25" 

the badgevalue gets changed number before disappearing, i'm using instruction

print("badge value:\(navigationitem.rightbarbuttonitem?.badgevalue any)") 

so value there because in debug console:

badge value: optional("40") 

but unknown reason disappears

udate 2

 self.navigationcontroller!.pushviewcontroller(destviewcontroller, animated: false) 

i discovered if turn off animation badgevalue doesn't disappear, need animation work too.

i found solution , it's simple actually, avoid behavior badgevalue should set in viewdidlayoutsubviews() instead of viewdidload()

override func viewdidlayoutsubviews() {     var numeroproductos = string(carrito.numprod)     carritobutton.badgevalue = numeroproductos } 

edit mikemtol's library buggy , causes lot of problems not 1 swift users recommend these extensions instead. -> link


Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -