2011-01-08 3 views
1

アレイから3つの異なるイメージをUITableの対応するセルにロードしようとしています。これまでのところ、私はtが実行されたときに細かいクラッシュを生成する次のコードを持っています。私はfanyoneが私を助けることができてとても感謝しています。アレイからUITabeViewに別のイメージをロードする

- (void)viewDidLoad { 
NSArray *array = [[NSArray alloc] initWithObjects:@"Icon Nightclub", @"Smyhts Bar", 
     @"Synotts",nil]; 
self.listData = array; 


NSArray *picArray = [[NSArray alloc] initWithObjects:@"ArrowLeftDefault.png", @"ArrowRightDefault.png", 
     @"events.png",nil]; 
self.picData = picArray; 


[array release]; 
[picArray release]; 
[super viewDidLoad]; 

} 


-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
return [listData count]; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
static NSString *SimpleTableIdentifier = @"SimpleTableIdentifier"; 
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:SimpleTableIdentifier]; 

if (cell == nil) { 
    cell = [[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:SimpleTableIdentifier] autorelease]; 
} 

NSUInteger row = [indexPath row]; 
cell.textColor = [UIColor grayColor]; 
cell.textLabel.text = [listData objectAtIndex:row]; 
cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton; 

cell.imageView.image = [picData objectAtIndex:indexPath.row]; 

return cell; 

} 

答えて

4

変更:

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

説明:このような何かのために

cell.imageView.image = [picData objectAtIndex:indexPath.row]; 

picData NSArrayNSString Sが含まれているので、あなたがcell.imageView.imageNSStringオブジェクトを渡しましたUIImageオブジェクトを期待していますtually。 これは、イメージを作成して渡す理由です。 (imageNamed:メソッドがイメージをキャッシュします)

+0

あなたは私よりも速いです。 :)はい、これが答えです。 picData配列にはUIImagesではなく文字列の配列が含まれているため、コードがクラッシュしています – Walter

+0

ああ素晴らしいです。乾杯。私はそれを見つけたはずです。私はこれほど長くはない。あなたは私のベーコンを救った。 – krosullivan

+0

Walterさん、ありがとうございました。 – nacho4d

関連する問題