0

AppDelegate.h:

@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;
}

In someOtherMethod in AppDelegate.m:

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

Why? Other methods in the interface are visible, but why isn't this one? Does it have to do with being a Class method?

soleil
  • 12,133
  • 33
  • 112
  • 183
  • 1
    + is a class method, - is an instance method. You don't execute that method on self, you execute it on AppDelegate. You likely want to change the definition to -. – Stefan H Sep 12 '12 at 06:04
  • @StefanH that makes sense, but why can't I do this either (from a different class): AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate]; [appDelegate showGlobalProgressHUDWithTitle:@"whatever"]; – soleil Sep 12 '12 at 06:08
  • 1
    Because `[[UIApplication sharedApplication] delegate]` returns an instance of `AppDelegate`, not the class itself. To call the class method you need to do `[AppDelegate classMethodName]`. – Rog Sep 12 '12 at 06:11

1 Answers1

2

You're calling a class method from an object instance (self).

Change + to - in your method declaration and implementation, and you're sorted.

Rog
  • 18,602
  • 6
  • 76
  • 97