ios - Which is the better way to remove self from NSNotificationCenter? Just remove self or remove self from the specific notification name? -


i want know: better way remove self nsnotificationcenter in dealloc method? or have met different behaviors between 2 way?

just remove self follow code:

[[nsnotificationcenter defaultcenter] removeobserver:self]; 

or remove self specific notification name this:

[[nsnotificationcenter defaultcenter] removeobserver:self name:notificationname object:someobj]; 

ps. catch weird thing when remove self notification center first way object dealloced still can receive notification, , call crash exception of course.

[[nsnotificationcenter defaultcenter] removeobserver:self]; 

that remove registrations observer self

uiviewcontroller have own registrations doesn't want removed in viewwilldisappear:. it's unlikely register of notifications in public api using addobserver:selector:name:object:, because preclude registering them in uiviewcontroller subclass, register non-public notifications or in future version.

a safe way deregister send removeobserver:name:object: once each registration:

- (void)deregisterfornotifications { nsnotificationcenter *center = [nsnotificationcenter defaultcenter]; [center removeobserver:self name:somenotification object:nil]; object:nil]; } 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -