Reputation: 11
I'm wondering what happens in this case of class hierarchy
MySuperClass : UIViewController
MYSubClass : MySuperClass
MySuperClass lack the method, ViewWillAppear
My question is: if MySubClass has the following method
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
}
is that code simply ignored (won't be executed) or viewWillAppear in UIViewController will be called?
Just wondering.
Upvotes: 1
Views: 620
Reputation: 125037
Say you have:
MySubClass *mySubController = [[MySubClass alloc] initWithNibNamed:nil bundle:nil];
If you do something with mySubController that will cause its view to appear, like push it onto a nav controller's stack, then MySubClass' implementation of -viewWillAppear will be called. As it is now, that implementation just calls super's implementation. Since MySuperClass doesn't override -viewWillAppear, UIViewController's implementation will be called.
Upvotes: 0
Reputation: 39925
It works similarly to normal method calls. When you call on super, the runtime goes up through the chain of superclasses until it finds one that implements the requested method. If it doesn't find one, it will call forwarding methods, and if the method isn't forwarded it will call doesNotRecognizeSelector:
. So, yes, viewWillAppear
will be called on the UIViewController class.
Upvotes: 3