In my little iPad app I have a "switch language" function that uses an observer. Every view controller registers itself with my observer during its viewDidLoad:
.
- (void)viewDidLoad
{
[super viewDidLoad];
[observer registerObject:self];
}
When the user hits the "change language" button, the new language is stored in my model and the observer is notified and calls an updateUi:
selector on its registered objects.
This works very well, except for when I have view controllers in a TabBarController. This is because when the tab bar loads, it fetches the tab icons from its child controllers without initializing the views, so viewDidLoad:
isn't called, so those view controllers don't receive language change notifications. Because of this, I moved my registerObject:
calls into the init
method.
Back when I used viewDidLoad:
to register with my observer, I used viewDidUnload:
to unregister. Since I'm now registering in init
, it makes a lot of sense to unregister in dealloc
.
But here is my problem. When I write:
- (void) dealloc
{
[observer unregisterObject:self];
[super dealloc];
}
I get this error:
ARC forbids explicit message send of 'dealloc'
Since I need to call [super dealloc]
to ensure superclasses clean up properly, but ARC forbids that, I'm now stuck. Is there another way to get informed when my object is dying?
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…