0

ファイル名とサムネイルのリストを含むtableViewを作成しています。ファイル名に問題はありませんが、 UIImage 配列を tabeView に渡すと、エラーが発生します。コードは次のとおりです。

cell.imageView.image = [UIImage imageNamed:[arrayColletionImages objectAtIndex:indexPath.row]];

私が取得したarrayColletionImages画像:

player = [[MPMoviePlayerController alloc] initWithContentURL:url];
thumbnail = [player thumbnailImageAtTime:0.0 timeOption:MPMovieTimeOptionExact];
[player stop];
[arrayColletionImages addObject:thumbnail];

すべての UITableViewCell コード:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = @"SimpleTableItem";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}
cell.textLabel.text = [tableData objectAtIndex:indexPath.row];
cell.imageView.image = [UIImage imageNamed:[arrayColletionImages objectAtIndex:indexPath.row]];
NSLog(@"%@",indexPath);
return cell;
}
4

2 に答える 2

0

配列に UIImage オブジェクトが含まれていない可能性があります。配列の値をログに記録します

<UIImage: 0xa8a5430>ログでは、それが UIImage オブジェクトであることを意味し、cellForRowコードではそれを再び使用しています。

cell.imageView.image = [UIImage imageNamed:[arrayColletionImages objectAtIndex:indexPath.row]];

UIImage imageNamed:UIImageではなくNSStringを期待するので、これを削除してください

cell.imageView.image = [UIImage imageNamed:[arrayColletionImages objectAtIndex:indexPath.row]];

コードでこれを試してください

[cell.imageView setImage:[arrayColletionImages objectAtIndex:indexPath.row]];
于 2013-05-13T12:11:10.597 に答える
0

これを使ってみてください。配列から画像名にアクセスしています. しかしUIImage, この配列にはすでにオブジェクトが保存されています. 呼び出す必要はありません.imageNamed: だからこの行を書きます.

cell.imageView.image = [arrayColletionImages objectAtIndex:indexPath.row];
于 2013-05-13T12:11:19.893 に答える