2010-01-18 44 views
0

我已经花了今天早上搜索谷歌这一点,但我无法得到我想要的,我想如何。iPhone开发问题帮助形成数组

我正在创建一个自定义表格视图单元格,在不同的图标下方,在分段表格视图中。我的问题是我无法从数组中读取这些图像。 我可以像下面这样做,但有人可以帮我从数组中做这件事。

长时间工作表单代码:

switch (indexPath.row) { 
    case 0: 
    imageView2.image = [UIImage imageNamed:@"ico-company.png"]; break; 
    case 1: 
    imageView2.image = [UIImage imageNamed:@"ico-value.png"]; 
    case 2: 
    imageView2.image = [UIImage imageNamed:@"ico-date.png"]; break; 
    case 3: 
    imageView2.image = [UIImage imageNamed:@"ico-notes.png"];break; 
    default: 
    break; 
    } 

,我想我可以得到它看起来像:

不工作的代码,我想怎么

arryImages = [[NSMutableArray alloc] init]; 
    arryImages = [NSArray arrayWithObjects: 
      [UIImage imageNamed: @"ico-company.png"], 
       [UIImage imageNamed: @"ico-value.png"], 
       [UIImage imageNamed: @"ico-date.png"], 
       [UIImage imageNamed: @"ico-notes.png"], nil]; 

    imageView2.image = [UIImage imageWithContentsOfFile:[arryImages objectAtIndex:[indexPath row]]]; 

而且这是我得到的错误,当我尝试我的数组代码:

2010-01-18 13:20:47.314 SQL[60921:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[UIImage length]: unrecognized selector sent to instance 0x39135c0' 

问候

回答

4

你的最后一行实际上应该是:

imageView2.image = [arryImages objectAtIndex:[indexPath row]]; 

(在你的代码,你传递的图像对象imageWithContentsOfFile,但这种方法需要一个文件名,而不是一个图像对象)

+0

完美答案! – oberbaum 2010-01-18 12:49:54