Lalalalalala
Lalalalalala

Reputation: 167

How would I use a string of image names to use in a UIImageView?

I keep ending with an error saying that there are incompatible pointers assigning UIIMAGE to NSString.

self.imageNames = [NSArray arrayWithObjects:@"shop_deal.png",@"Date.png",@"Recreation.png",@"Productivity.png",nil];

        UIImageView *imgView =[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 320, 150)];
        imgView.image = [UIImage imageNamed:_imageNames];
        [self addSubview:imgView];

I'm doing something wrong here...

Upvotes: 0

Views: 116

Answers (1)

Levi
Levi

Reputation: 7343

In this line:

imgView.image = [UIImage imageNamed:_imageNames]; 

you have to use an NSString, not an entire NSArray. So try:

imgView.image = [UIImage imageNamed:[_imageNames objectAtIndex:0]]; 

instead.

Upvotes: 4

Related Questions