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 に答える