我正在使用故事板執行我的項目,並試圖實施自定義UITableViewCell
。使用故事板時自定義uitableviewcell
我願做我的自定義單元格如下:
#import "CustomCell.h"
@implementation CustomCell
@synthesize myLabel, myButton;
- (instancetype)initWithCoder:(NSCoder *)decoder
{
if ((self = [super initWithCoder:decoder]))
{
//want to custom setup of properties placed in the cell
self.myButton.backgroundColor = [UIColor redColor];//this does NOT work
//and so forth...
}
return self;
}
但底色未設置。它只有當我設置在tableViewController
的cellForRowAtIndexPath
功能按鈕的背景顏色,這樣
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:@"CustomCell"];
MyObject *obj = self.myObjects[indexPath.row];
cell.myButton.backgroundColor = [UIColor redColor];//This works!
cell.myLabel.text = obj.name;
return cell;
}
作品和我已經設置斷點和NSLog
嘗試調試和initWithCoder
被cellForRowAtIndexPath
之前要求的每一個細胞?? 但是當我將它設置在自定義單元格中時,單元格中按鈕的背景顏色不顯示。
任何幫助?
爲什麼不在故事板中設置backgroundColor? –