objective c - iOS - Swapping View Controller's in a Container View and persisting the data -
i have container view swaps child view controllers. upon swapping view controllers though lose data controller had when deallocated memory.
how can swap child view controllers , keep data same way tab bar controller swaps them without losing deallocating data memory?
you should have outer (root) viewcontroller persists, , owns containerview , cycling child viewcontrollers. ideally rootviewcontroller (or other object outlives individual child viewcontrollers eg appdelegate) own strong reference model, , childviewcontrollers given weak pointer model life cycle. easier if these childviewcontrollers inherit abstract superclass has weak property point model object, rootviewcontroller can treat children instance of superclass.
edit/additional info.... make new subclass of nsobject properties of data want persist. call somethingmodel remove variables/properties data childrenviewcontrollers , give them @property (weak, nonatomic) somethingmodel *modelobject (put in subclass on uiviewcontroller, , make childrenviewcontrollers subclasses of that... give outer(root) viewcontroller similar property, make 1 strong rather weak. when create new childcontroller need set modelobject property , you're done :)
Comments
Post a Comment