2012-09-12 19 views
0

AppDelegate.h:爲AppDelegate中無可見接口聲明的選擇

@interface AppDelegate : UIResponder <UIApplicationDelegate, UITabBarControllerDelegate> 

+ (MBProgressHUD *)showGlobalProgressHUDWithTitle:(NSString *)title; 

AppDelegate.m:

+ (MBProgressHUD *)showGlobalProgressHUDWithTitle:(NSString *)title { 
UIWindow *window = [[[UIApplication sharedApplication] windows] lastObject]; 
[MBProgressHUD hideAllHUDsForView:window animated:YES]; 
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:window animated:YES]; 
hud.labelText = title; 
return hud; 
} 

在someOtherMethod在AppDelegate.m:

[self showGlobalProgressHUDWithTitle:@"Checking for Updates"]; //No visible interface for AppDelegate declares the selector 'showGlobalProgressHUDWithTitle:' 

爲什麼?界面中的其他方法是可見的,但爲什麼不是這個?它與做類方法有關嗎?

+1

+是一個類方法, - 是一個實例方法。你不用自己執行這個方法,你可以在AppDelegate上執行它。您可能想要將定義更改爲 - 。 –

+0

@StefanH有道理,但爲什麼我不能這樣做(從不同的類):AppDelegate * appDelegate =(AppDelegate *)[[UIApplication sharedApplication] delegate]; [appDelegate showGlobalProgressHUDWithTitle:@「whatever」]; – soleil

+1

因爲[[[UIApplication sharedApplication]委託]'返回'AppDelegate'的一個實例,而不是類本身。要調用這個類方法,你需要執行'[AppDelegate classMethodName]'。 – Rog

回答

1

你從一個對象實例(self)調用一個類方法。

在方法聲明和實現中更改+ to - 並對其進行排序。

相關問題