【发布时间】:2016-05-28 16:14:34
【问题描述】:
我有一个自定义 UITableViewCell ,其中我有两个 UIViews 。我想更改 UIViews 的 BackgroundColor 半径和更多属性。
但我做不到。
这是我的设置。
第 1 步:
Create A Custom Cell with XIB.
第 2 步:在 XIB 中为 CustomCell 输入 Cell Identifer 名称。
第 3 步:在 viewDidLoad 中实例化 NIB
UINib *nib = [UINib nibWithNibName:@"CustomCell" bundle:nil];
[[self mTableView] registerNib:nib forCellReuseIdentifier:@"CustomCell"];
第 4 步:索引方法中的行单元格:
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// Create an instance of ItemCell
CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CustomCell"];
[cell updateCellView];
return cell;
}
第 5 步:检查两次插座连接一切正常。
第 6 步:自定义单元格类:
#import "TransportCell.h"
@implementation TransportCell
- (void)awakeFromNib {
// Initialization code
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
- (void)updateCellView
{
self.backgroundView.backgroundColor = [UIColor redColor];
}
@end
此代码对我的单元格视图没有影响。
我调试代码。当我登录backgroundView 时,当updateCellView 方法被调用时,我得到nil:
这是我的 CustomCell 的 Xib:
我必须更改内部 UIView 的属性。(蓝色)
【问题讨论】:
-
试试 self.backgrondColor = [UIColor redcolor]
-
它会改变单元格背景颜色
-
你为你的背景视图做了出口还是连接到你的视图?
标签: ios objective-c uitableview ios7 tableviewcell