ios - The navigation controller delegate method is not getting a call -


in following code, trying create custom animator during navigation transition navigation controller delegate method not getting call. please @ below code , suggest me solution.

please note have embedded demotransitionanimationviewcontroller in navigation controller. vc has button on view. on click of view pushing view controller. still delegate method not getting call.

customanimator.swift

// //  customanimator.swift //  loginmodule // //  created shubham ojha on 8/14/17. //  copyright © 2017 bbi. rights reserved. //  class fadeinanimator: nsobject, uiviewcontrolleranimatedtransitioning {     func transitionduration(         using transitioncontext: uiviewcontrollercontexttransitioning?         ) -> timeinterval {         return 0.35      }     func animatetransition(using transitioncontext: uiviewcontrollercontexttransitioning) {         let containerview = transitioncontext.containerview         let fromvc = transitioncontext.viewcontroller(             forkey: uitransitioncontextviewcontrollerkey.from)         let tovc = transitioncontext.viewcontroller(             forkey: uitransitioncontextviewcontrollerkey.to)          containerview.addsubview(tovc!.view)         tovc!.view.alpha = 0.0          let duration = transitionduration(using: transitioncontext)         uiview.animate(withduration: duration, animations: {             tovc!.view.alpha = 1.0             tovc?.view.backgroundcolor = uicolor.blue         }, completion: { finished in             let cancelled = transitioncontext.transitionwascancelled             transitioncontext.completetransition(!cancelled)         })     }  }  class navigationcontrollerdelegate: nsobject, uinavigationcontrollerdelegate {      func navigationcontroller(         _ navigationcontroller: uinavigationcontroller,         animationcontrollerfor operation:         uinavigationcontrolleroperation,         fromvc: uiviewcontroller,         tovc: uiviewcontroller         ) -> uiviewcontrolleranimatedtransitioning? {          return fadeinanimator()      } } 

demotransitionanimationviewcontroller.swift

// //  demotransitionanimationviewcontroller.swift //  loginmodule // //  created shubham ojha on 8/15/17. //  copyright © 2017 bbi. rights reserved. //  import uikit  class demotransitionanimationviewcontroller: uiviewcontroller {      override func viewdidload() {         super.viewdidload()         print(self.navigationcontroller ?? "not exist")          if self.navigationcontroller != nil{             self.navigationcontroller?.delegate = navigationcontrollerdelegate()        // in above statement if setting delegate self instead of        //navigationcontrollerdelegate() , conforming methods of navigation        //controller delegate protocol. works perfectly.         }         else{             print("navigation controller not exist")         }      }  } 

try this:

if self.navigationcontroller != nil{    self.navigationcontroller?.delegate = self // update assignment here } else {     print("navigation controller not exist") } 

self.navigationcontroller?.delegate = navigationcontrollerdelegate() independent (without reference of uiviewcontroller) memory allocation. so, won't respond implementation of delegate methods of view controller.

self.navigationcontroller?.delegate = self tells navigation controller delegate use reference of view controller demotransitionanimationviewcontroller , consider implementation navigation.


Comments

Popular posts from this blog

PHP and MySQL WP -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

Why does math.random(999999999999) returns 1 in Lua? -