我正在开发一款带有robovm& amp;关于ios的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];
}
答案 0 :(得分:3)
您可以通过提供与父类名称相同的方法来覆盖您的方法:新方法将替换继承的定义。确保您的方法具有相同的返回类型,并采用与您覆盖的方法相同的参数数量和类型。
所以只需重新定义子类中的 -(void)viewWillAppear:(BOOL)animated
。
根据Apple Doc,不建议使用属性进行子类化。
答案 1 :(得分:1)
通常你有两种方式:
继承你的viewController并重新定义 - (void)viewWillAppear:(BOOL)动画
在UIViewController的类别中执行方法调配(参见例如Method Swizzle on iPhone device)