接收器类型'AppDelegate'例如消息没有声明具有选择器ERROR的方法

时间:2013-11-07 05:17:16

标签: objective-c appdelegate

似乎无法解决这个问题。知道需要改变什么吗?我正在使用Xcode 4.2。

错误: AppDelegate.m:23:6:错误:接收器类型'AppDelegate'例如消息未声明带有选择器'setupHUD'的方法[4]

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.window.backgroundColor = [UIColor whiteColor];

    LoginViewController *loginVC = [[LoginViewController alloc] init];
    UINavigationController *navCon = [[UINavigationController alloc] initWithRootViewController:loginVC];
    navCon.navigationBarHidden = YES;
    self.window.rootViewController = navCon;
    [self setupHUD];

    [self.window makeKeyAndVisible];
    return YES;
}


- (void) setupHUD
{
    //setup progress hud
    self.HUD = [[MBProgressHUD alloc] initWithFrame:self.window.bounds];
    [self.window addSubview:self.HUD];
    self.HUD.dimBackground = YES;
    self.HUD.minSize = CGSizeMake(150.f, 150.f);
    self.HUD.delegate = self;
    self.HUD.isCancelButtonAdded = YES;
    self.HUD.labelText = @"Loading";
}

1 个答案:

答案 0 :(得分:1)

Prior to Xcode 4.3,您需要转发在同一@implementation块内调用的声明方法,因此请确保将setupHUD的声明添加到类扩展(内部声明列表)中以@interface AppDelegate ())开头的AppDelegate.m,或AppDelegate.h中的@interface块。

例如,在AppDelegate.m中:

@interface AppDelegate ()
// Other declarations...
- (void)setupHUD;
@end

或者在AppDelegate.h中:

@interface AppDelegate : NSObject <UIApplicationDelegate>
// Other declarations
- (void)setupHUD;
@end