Zugriff auf Array-Objekt
Ich erstelle ein Array und initialisiere es mit Objekten. Ich habe versucht, Zugriff auf das Array-Objekt zu bekommen, aber ich bekomme eine (null). was mache ich falsch
photoArray = [[NSMutableArray alloc] init];
PhotoItem *photo1 = [[PhotoItem alloc] initWithPhoto:[UIImage imageNamed:@"1.jpg"] name:@"roy rest" photographer:@"roy"];
PhotoItem *photo2 = [[PhotoItem alloc] initWithPhoto:[UIImage imageNamed:@"2.jpg"] name:@"roy's hand" photographer:@"roy"];
PhotoItem *photo3 = [[PhotoItem alloc] initWithPhoto:[UIImage imageNamed:@"3.jpg"] name:@"sapir first" photographer:@"sapir"];
PhotoItem *photo4 = [[PhotoItem alloc] initWithPhoto:[UIImage imageNamed:@"4.jpg"] name:@"sapir second" photographer:@"sapir"];
[photoArray addObject:photo1];
[photoArray addObject:photo2];
[photoArray addObject:photo3];
[photoArray addObject:photo4];
Ich versuche, Zugriff auf eines der Objekte durch diese Codezeile zu erhalten (die zurückgibt (null)):
photoName.text = [NSString stringWithFormat:@"%@", [[photoArray objectAtIndex:2] nameOfPhotographer]]
Update: Code des Fotoartikels:
-(id)initWithPhoto:(UIImage*)image name:(NSString*)photoName photographer:(NSString*)photographerName
{
self = [super init];
if(self)
{
imageItem = image;
name = photoName;
nameOfPhotographer = photographerName;
//[self setName:photoName];
//[self setNameOfPhotographer:photographerName];
//[self setImageItem:image];
}
return self;
}
worin besteht das Problem?
Danke !!