1

私はiPhone開発に不慣れです.各セルに画像を表示したい.私は配列に画像のURLしか持っていません.助けてください.ありがとう.

4

2 に答える 2

4
//put this code in cellForRowAtIndexPath.... I'm assuming you have an array of url's that point to images
id urlPath = [yourArray objectAtIndex:indexOfImage];
NSURL *url = [NSURL URLWithString:urlPath];
NSData *data = [NSData dataWithContentsOfURL:url];
UIImage *image = [UIImage imageWithData:data];


static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}   

//insert an image into your cell
cell.imageView = image;

これを行うにはもっと効率的な方法があるかもしれませんが、テーブルビュー セルのカスタマイズを開始するには適切な方法です。ImageView は、UITableViewCell クラスの多くのプロパティの 1 つです。

さらに読む.... UITableViewCellクラスリファレンス

于 2010-02-08T21:24:49.957 に答える
2

このリンゴのサンプルコードを見てください。これは素晴らしく、必要なものとその他の便利なものを実装する方法を示しています: Advanced Table View Cells

于 2010-02-08T21:36:04.613 に答える