2

UITableViewセルにUIImageViewを追加しましたが、表示されません。しかし、行を選択すると、画像が表示され、非常に困惑します。手伝って頂けますか ?

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier: (NSString *) reuseIdentifier    
{  
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        cellImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"one.png"]];       
        cellImage.frame = CGRectMake(240, 0, 20, 20);
        [self.contentView addSubview:cellImage];
        self.textLabel.text = @"parent";
    }
    return self;
}
4

2 に答える 2

0

cellImageとして追加する必要がありaccessoryViewます。

[cell setAccessoryView: cellImage];
于 2012-06-02T04:19:50.070 に答える
0

最初にimageViewを初期化し、そのフレームを設定する必要があります。次に、その画像を設定する必要があります。CustomtableViewCellの指定されたコードを参照してください。

imgView = [[UIImageView alloc] initWithFrame:CGRectMake(3, 3, 80, 80)];
imgView.contentMode = UIViewContentModeScaleAspectFit;
[self.contentView addSubview:imgView];

これで、コントローラーのtableViewCellforrowatindexpathメソッドで、指定されたコードが使用されます

static NSString *CellIdentifier = @"Cell";

CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.imgView.image = [UIImage imageNamed:@"123.jpg"];

これにより、urimgViewに画像が追加されます

于 2012-07-12T10:03:35.763 に答える