我在iOS項目中有幾個hunderd .jpgs
在/Resources
中。從NSArray中將圖像加載到UITableViewCell中
這裏是viewDidLoad方法:
- (void)viewDidLoad {
NSArray *allPosters = [[NSBundle mainBundle] pathsForResourcesOfType:@"jpg" inDirectory:@"."];
[super viewDidLoad];
}
上面成功地加載所有.jpgs
的成NSArray
。 我只需要這個數組內UITableViewCells
在UITableView
這裏顯示的所有.jpgs
的是-(UITableViewCell *)tableView:cellForRowAtIndexPath:
方法:
-(UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
NSDictionary *posterDict = [allPosters objectAtIndex:indexPath.row];
NSString *pathToPoster= [posterDict objectForKey:@"image"];
UITableViewCell *cell =
[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell ==nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]autorelease];
}
UIImage *theImage = [UIImage imageNamed:pathToPoster];
cell.ImageView.image = [allPosters objectAtIndex:indexPath.row];
return cell;
}
我知道這個問題是與cell.ImageView.image
,但我不知道是什麼問題是什麼?我如何從陣列中抓取每個.jpg
並在每一行中顯示?
謝謝,雖然我收到'請求會員'ImageView'的東西不是結構或聯盟'? – mozzer 2011-03-07 14:38:06
噢,沒有發現。當然是cell.imageView.image。沒有資本我 – 2011-03-07 14:39:36