i subclassed uinavigationcontroller
, through didshow
delegate, called whenever new view controller pushed onto stack, update instance variable called previousviewcontroller
(to able perform custom work).
the instance variable:
class sectionnavigationcontroller: uinavigationcontroller { var previousviewcontroller: uiviewcontroller? ...
the delegate updated:
// nav controller delegate method (did show) func navigationcontroller(_ navigationcontroller: uinavigationcontroller, didshow viewcontroller: uiviewcontroller, animated: bool) { if currentindex! > 0 { previousviewcontroller = navigationcontroller.viewcontrollers[currentindex! - 1] } }
consequence, however, whenever poptorootviewcontroller
called, view controller underneath top view controller (previousviewcontroller
) not deinitialized because of reference. how can override poptorootviewcontroller
in such way append deinitialization of previousviewcontroller
?
check this apple documentation
you resolve strong reference cycles defining of relationships between classes weak or unowned references instead of strong references.
you should declare var
weak
Comments
Post a Comment