Reputation: 744
I tried to load a image inside table view cells image view from a NSMutableArray. But I get warning Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIImage length]: unrecognized selector sent to instance.
I tried many solutions posted in this site. But it is not working for me.
This is my code :
recipe1.numbers1=[[NSMutableArray alloc] initWithObjects:
[UIImage imageNamed:@"1.png"],
[UIImage imageNamed:@"2.png"],
[UIImage imageNamed:@"3.png"],
[UIImage imageNamed:@"4.png"],
[UIImage imageNamed:@"5.png"],
[UIImage imageNamed:@"6.png"],
[UIImage imageNamed:@"7.png"],
[UIImage imageNamed:@"8.png"],
[UIImage imageNamed:@"9.png"],
[UIImage imageNamed:@"10.png"], nil];
This is how i access those images:
cell1.numbersImageview1.image = [UIImage imageNamed:[recipe.numbers1 objectAtIndex:indexPath.row]];
Upvotes: 2
Views: 7165
Reputation: 762
you try this one also once.
- (void)viewDidLoad
{
recipe1.numbers1=[[NSMutableArray alloc] initWithObjects:@"1.png",@"2.png",@"3.png",@"4.png",@"5.png",@"6.png",@"7.png",@"8.png",@"9.png",@"10.png"];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
....................
....................
NSString *imagename=[recipe1.numbers1 objectAtIndexPath:indexPath.row];
cell1.numbersImageview1.image =[UIImage imageNamed:imagename];
}
Upvotes: 0
Reputation: 3815
You are doing it wrong change this line :
cell1.numbersImageview1.image = [UIImage imageNamed:[recipe.numbers1 objectAtIndex:indexPath.row]];nil];
TO
cell1.numbersImageview1.image = [recipe1.numbers1 objectAtIndex:indexPath.row];
Upvotes: 0
Reputation: 5499
The error is the way you are accessing the image from the array, you already store an UIImage
object there, there is no need (and is an error) to call imageNamed:
, change the line to:
cell1.numbersImageview1.image = [recipe.numbers1 objectAtIndex:indexPath.row];
EDIT
In your code you are adding the access to the elements of the array as another object, try changing the whole code to this:
recipe1.numbers1=[[NSMutableArray alloc] initWithObjects:
[UIImage imageNamed:@"1.png"], [UIImage imageNamed:@"2.png"],
[UIImage imageNamed:@"3.png"], [UIImage imageNamed:@"4.png"],
[UIImage imageNamed:@"5.png"], [UIImage imageNamed:@"6.png"],
[UIImage imageNamed:@"7.png"], [UIImage imageNamed:@"8.png"],
[UIImage imageNamed:@"9.png"], [UIImage imageNamed:@"10.png"], nil];
cell1.numbersImageview1.image = [recipe.numbers1 objectAtIndex:indexPath.row];
Upvotes: 2