2012-06-02 92 views
2

我在UITableView Cell中添加了UIImageView,但它不可見。 但是,當你選擇了行,圖像是可見的,它是如此困惑。 你能幫助我嗎?UIImageView在UITableViewCell中不可見

- (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; 
} 

回答

0

你應該只添加cellImageaccessoryView

[cell setAccessoryView: cellImage]; 
+0

它的工作原理,謝謝。 – haibarahu

0

你應該首先初始化您的ImageView,並設置其框架 那麼你應該設置其image.See給定的代碼爲CustomtableViewCell

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

現在在你的控制器的tableViewCellforrowatindexpath方法 的UE給定的代碼

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"]; 

這將在烏爾imgView添加圖像

相關問題