ios - How should I tidy UIViewControllers when they need to be destroyed -
i'm starting write second version of our iphone app , i'm trying tidy previous mistakes (as it's first attempt @ objective-c). question related "things need when uiviewcontroller destroyed", there seem few contradictory answers out there , want make sure understand correctly.
couple of constraints:
- this code use ios 5 , ios 6 devices
- i don't wish register , deregister nsnotifications on viewwillappear , viewwilldisappear because uiviewcontrollers need receive notifications if can't seen user.
- i'm using storyboard rather separate nib files.
so considering above constraints, following statements true?
- iboutlets connecting storyboard uiviewcontrollers should weak, strong reference created behind scenes.
- because iboutlets weak shouldn't need nil them out in low memory situations
- i shouldn't use viewdidunload because it's being deprecated instead should use didreceivememorywarning. in situation need nil out strong properties (that can re-calculated)
- it's acceptable register nsnotifications on viewdidload.
- because wish continue receiving notifications when view hidden, best place unregister them in dealloc, there's no benefit in unregistering them in didreceivememorywarning.
thanks help,
dan
iboutlets connecting storyboard uiviewcontrollers should weak, strong reference created behind scenes.
no. nskeyedunarchiver (nscoder) not change storage qualifiers associated user-created outlets. keep them weak because don't ever explicitly alloc , init iboutlets, therefore not "own" them in cocoa sense of word.
because iboutlets weak shouldn't need nil them out in low memory situations
not true @ all. zeroing weak references 0 out in dealloc, not in low memory situations. apple expects explicitly releasing strong outlets handle memory warnings.
i shouldn't use viewdidunload because it's being deprecated instead should use didreceivememorywarning. in situation need nil out strong properties (that can re-calculated)
yes, replacement -viewdidunload, dealloc serves purpose.
it's acceptable register nsnotifications on viewdidload. because wish continue receiving notifications when view hidden, best place unregister them in dealloc, there's no benefit in unregistering them in didreceivememorywarning.
absolutely.
Comments
Post a Comment