我想創建一個自定義的UITableViewCell。創建一個自定義的UITableViewCell
從XCode 4.6界面構建器中,我已將單元格的Style
屬性設置爲Custom。並使用拖放功能將控件添加到單元格中。 2個UILables和一個UIButton。它看起來像這樣。
我創建一個單獨的類從的UITableViewCell推導來分配3種UI元素的屬性,並進行相應的修改。我已經從Identity Inspector將單元的自定義類設置爲DashboardCell。
DashboardCell.h
DashboardCell.m
#import "DashboardCell.h"
@implementation DashboardCell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
[self.numberOfOverdueMails setBackgroundColor:[UIColor colorWithRed:244/255.0f green:119/255.0f blue:125/255.0f alpha:1.0f]];
[self.numberOfOverdueMails setTitle:@"lol" forState:UIControlStateNormal];
}
return self;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
@end
在TableViewController,我已經修改了下面的方法來恢復我的自定義單元格。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
DashboardCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
if (cell == nil) {
cell = [[DashboardCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
return cell;
}
我的問題是,即使自定義按鈕顯示了,我已經做了改變(改變按鈕的背景顏色,改變一個的UILabel的標題)沒有顯示出來。這裏似乎有什麼錯誤?