0
AppDelegate.h를 선언하지 :AppDelegate에 대한 눈에 띄는 인터페이스는 선택
@interface AppDelegate : UIResponder <UIApplicationDelegate, UITabBarControllerDelegate>
+ (MBProgressHUD *)showGlobalProgressHUDWithTitle:(NSString *)title;
AppDelegate.m : AppDelegate.m에서 someOtherMethod에서
+ (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;
}
:
[self showGlobalProgressHUDWithTitle:@"Checking for Updates"]; //No visible interface for AppDelegate declares the selector 'showGlobalProgressHUDWithTitle:'
이유는 무엇입니까? 인터페이스의 다른 메소드가 표시되지만이 메소드가 아닌 이유는 무엇입니까? 그것은 클래스 메소드가되는 것과 관련이 있습니까?
+는 클래스 메소드이며, - 인스턴스 메소드입니다. 이 메소드를 자체에서 실행하지 않으면 AppDelegate에서 실행합니다. 정의를 -로 변경하려고합니다. –
@StefanH는 의미가 있지만 왜 다른 클래스에서이 작업을 수행 할 수 없습니까? AppDelegate * appDelegate = (AppDelegate *) [[UIApplication sharedApplication] delegate]; [appDelegate showGlobalProgressHUDWithTitle : @ "무엇이든"]; – soleil
'[[UIApplication sharedApplication] delegate]'는 클래스 자체가 아닌'AppDelegate' 인스턴스를 반환합니다. 클래스 메소드를 호출하려면'[AppDelegate classMethodName]'을해야한다. – Rog