未找到实例方法alloc

时间:2011-11-21 18:31:39

标签: iphone objective-c ios

我写了这段代码。我按照facebook SDK提供的示例应用程序代码。 在FeceAppDelegate.m

#import "FaceAppDelegate.h"

#import "FaceViewController.h"

@implementation FaceAppDelegate

@synthesize window = _window;
@synthesize viewController = _viewController;
@synthesize navigationController=_navigationController;

@synthesize facebook;


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    FaceViewController *FaceViewController = [[FaceViewController alloc] init];
    UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:FaceViewController];
       // Initialize Facebook
    facebook = [[Facebook alloc] initWithAppId:@"345678" andDelegate:FaceViewController];


    self.window.rootViewController = self.viewController;
    [self.window makeKeyAndVisible];
    return YES;
}

当我运行时,我有EXC_BAD_ACCESS,并且我有一个警告,“未找到实例方法alloc ...” 我认为问题在于

FaceViewController *FaceViewController = [[FaceViewController alloc] init];

1 个答案:

答案 0 :(得分:6)

第一个评论是正确答案。当你这样做时:

FaceViewController *FaceViewController = [[FaceViewController alloc] init];

您已将FaceViewController重新定义为当前范围内的实例变量,因此alloc将被发送到没有alloc方法的实例。更改您的实例var名称,它将起作用。惯例是从变量名称的小写开始,例如faceViewController