1

我的构造函数越来越出名"unrecognized selector sent to instance"。可能我缺少一些非常简单的东西。

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Problem on the next line:

    UserFetcher* userFetcher = [[UserFetcher alloc] initWithEmail:[self email] AndPassword:[self password]]; 

    [userFetcher fetch];
}

UserFetcher.h

-(id)initWithEmail:(NSString*)theEmail AndPassword:(NSString*)thePassword;

-(void)fetch;

UserFetcher.m

-(id)initWithEmail:(NSString*)theEmail AndPassword:(NSString*)thePassword AndDelegate: (id<UserFetcherDelegate>)theDelegate;
{
    if ([super init])
    {
        email = theEmail;
        password = thePassword;
    }
    return self;
}


-(void) fetch {...}

错误

2012-07-14 22:15:12.726 Project1[38478:c07] -[UserFetcher initWithEmail:AndPassword:]: unrecognized selector sent to instance 0x7af2ff0

任何想法缺少什么?

4

1 回答 1

2

你忘了那AndDelegate: (id<UserFetcherDelegate>)theDelegate;部分。此外,;从行尾删除 (在实现中)。应该是:

-(id)initWithEmail:(NSString*)theEmail AndPassword:(NSString*)thePassword
{
    if ([super init])
    {
        email = theEmail;
        password = thePassword;
    }
    return self;
}
于 2012-07-14T21:24:21.527 回答