2

我试图从 NSMutableArray 加载表格视图单元格图像视图中的图像。但是由于未捕获的异常'NSInvalidArgumentException',我收到警告 终止应用程序,原因:'-[UIImage 长度]:无法识别的选择器已发送到实例。

我尝试了该站点上发布的许多解决方案。但这对我不起作用。

这是我的代码:

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 = [UIImage imageNamed:[recipe.numbers1 objectAtIndex:indexPath.row]];
4

3 回答 3

2

错误是您从数组访问图像的方式,您已经在UIImage那里存储了一个对象,不需要(并且是错误)调用imageNamed:,将行更改为:

cell1.numbersImageview1.image = [recipe.numbers1 objectAtIndex:indexPath.row];

编辑

在您的代码中,您正在添加对数组元素的访问作为另一个对象,请尝试将整个代码更改为:

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];
于 2013-03-25T07:21:42.447 回答
0

你做错了改变这一行:

cell1.numbersImageview1.image = [UIImage imageNamed:[recipe.numbers1 objectAtIndex:indexPath.row]];nil];

cell1.numbersImageview1.image = [recipe1.numbers1 objectAtIndex:indexPath.row];
于 2013-03-25T07:22:22.870 回答
0
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];
}
于 2013-03-25T09:01:32.613 回答