2012-05-02 98 views
1

我有一個UIViewController與嵌入式tableview。 原型單元格已被定製(和子類別)以添加由平移手勢識別器啓動的「滑塊」效果。 我按照這個教程來做到這一點:https://github.com/spilliams/sparrowlike 在單元格內部,我有兩個視圖,一個可以滑開的前視圖和一個保持顯示其他控件的後視圖。動態添加圖像到原型自定義單元格

現在我需要爲每個單元格添加一個圖像,根據BOOL變量,將在兩個圖像之間選擇此圖像。

問題是:如果我以編程方式添加圖像視圖,圖像將被添加到單元格中,然後當用戶將前視圖劃掉時,圖像將保留在那裏。 所以圖像應該添加到前視圖中,但我無法在StoryBoard中添加圖像並添加一個插座。

所以問題是:我應該把代碼檢索自定義單元格子類中的圖像? 如果是這樣,我應該把它放在哪裏? 我「CustomCell」類實現文件看起來像這樣的時刻:

#import "CustomCell.h" 

@implementation CustomCell 
@synthesize frontView; 
@synthesize backView; 


- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier 
{ 
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; 
if (self) { 

} 
return self; 
} 

- (void)setSelected:(BOOL)selected animated:(BOOL)animated 
{ 
[super setSelected:selected animated:animated]; 

// Configure the view for the selected state 
} 

@end 

回答

1

什麼這樣的事情?

- (void)setupCell { 
    if (yourBoolValueHere) { 
     [[self frontView] setImage:[UIImage imageNamed:someImageName1]]; 
    } else { 
     [[self frontView] setImage:[UIImage imageNamed:someImageName2]]; 
    } 
    [[self view] bringSubviewToFront:[self frontView]]; 
} 

然後,你可以叫[cell setupCell]tableView:cellForRowAtIndexPath:

+0

不錯!非常感謝你。 – Aleph72

相關問題