简体   繁体   中英

What is meaning of calling superview's viewwillappear?

-(void)viewwillAppear
{
[super viewwillAppear:animated];
}

What does mean of calling [super viewwillAppear:animated] and what happen if we not call it?

By using super you are calling the base class version of the method. You will see similar call in init , dealloc , viewDidLoad etc. methods. The reason is in base class's implementation something important may be carried out without which the derived class will not work properly. When you have overridden the method in derived class, you will need to make a call to the base version by using super .

The only situation you will not call base class's method by using super is when you know that you don't need the tasks carried out by base class, in other words you are overriding completely. This is not the situation with viewWillAppear:animated or viewDidLoad etc. So we always call super in these cases.

The reference clearly states

This method is called before the receiver's view is about to be displayed onscreen and before any animations are configured for showing the view. You can override this method to perform custom tasks associated with presenting the view. For example, you might use this method to change the orientation or style of the status bar to coordinate with the orientation or style of the view being presented. If you override this method, you must call super at some point in your implementation.

Apple's documentation for viewWillAppear: just says:

If you override this method, you must call super at some point in your implementation.

It will probably lead to some unexpected behavior if you don't call it. Note that 'at some point' means you don't have to call it first.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM