我有一個需要從課內外調用的函數。下一個代碼工作正常,但我想知道,有沒有辦法只有一個lowerKeyboard
方法,而不是兩種方法 - 和+? 如果我將只保留+方法試圖從類例子和Class方法相同。可能?
內部調用的方法從類的內部時,我會得到一個錯誤unrecognized selector sent to instance
:
-(void)someOtherMethod
{
UIBarButtonItem *infoButtonItem=[[UIBarButtonItem alloc]initWithTitle:@"Done" style:UIBarButtonItemStyleDone target:self action:@selector(lowerKeyboard)];
}
從類的外部:
[myClass lowerKeyboard];
MyClass的:
-(void)lowerKeyboard
{
//do something
}
+(void)lowerKeyboard
{
//do the exact same thing
}
可能重複的[類和實例方法之間的區別是什麼?](http://stackoverflow.com/questions/1053592/what-is-the-difference-between-class-and-instance-methods) –
@DavidCaunt你看起來像破壞了壞!我不是在尋求差異,我知道差異。我的問題是如何結合這兩者。 – Segev
不,他長得像我! –