2014-01-26 60 views
1

我正在用robovm开发一款游戏&关于ios的libgdx,如何覆盖UIViewController.viewWillAppear如何覆盖iOS上的UIViewController函数?

(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]; 
} 

回答

1

由于通常有两种方式:

  • 子你的viewController,并重新定义 - (空)viewWillAppear中:(BOOL)动画

  • 类别为UIViewController中执行方法混写(见例如Method Swizzle on iPhone device

+0

谢谢你们,但我在Robovm上用Java开发游戏。 –

3

你c通过提供一个名称与您父类相同的方法来覆盖您的方法:该新方法将替换继承的定义。确保您的方法具有相同的返回类型,并采用与您覆盖的方法相同的参数数量和类型。

所以才重新定义在子类中-(void)viewWillAppear:(BOOL)animated

根据Apple Doc,不鼓励使用财产的子类别。