我在iOS上使用robovm和libgdx开发游戏,如何覆盖UIViewController.viewWillAppear
?
(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillShow:)
name:UIKeyboardWillShowNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillHide:)
name:UIKeyboardWillHideNotification
object:nil];
}
最佳答案
您可以通过提供与父类同名的方法来覆盖您的方法:新方法将替换继承的定义。确保您的方法具有与要覆盖的方法相同的返回类型,并采用相同数量和类型的参数。
因此,只需在子类中重新定义 -(void)viewWillAppear:(BOOL)animated
。
根据Apple Doc,不建议通过使用属性进行子类化。
关于ios - 如何在iOS上覆盖UIViewController的功能?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21362490/