我使用下面的代码更改我的自定义 uitableviewcell
标签的文本:
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
//NSArray *allsubviews = [[NSBundle mainBundle] loadNibNamed:@"LICustomUI" owner:nil options:nil];
//LIMerchantTableViewCell *cell = [allsubviews objectAtIndex:LIApplicationLayout() == LIApplicationDirectionRightToLeft ? 8 : 9];
let allSubViews = NSBundle.mainBundle().loadNibNamed("LICustomUI", owner: nil, options: nil)
var cell:LIInsuranceNameTableViewCell = allSubViews[11] as! LIInsuranceNameTableViewCell
cell.insuranceName.text = "Hello"
println(cell.insuranceName)
cell.insuranceName.backgroundColor = UIColor.redColor();
// cell.backgroundColor = UIColor.redColor();
return cell
}
println()
日志的结果是:
<UILabel: 0x7ad71930; frame = (0 11; 320 21); text = 'Hello'; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; layer = <_UILabelLayer: 0x7ad71a10>>
但在设备(模拟器)中文本没有改变!
最佳答案
如果您使用的是 Storyboard,请确保您已将标签连接到 insuranceName
导出(如果没有,只需按住 Control 键从标签拖动到您在助手中找到的导出检查员)。
此外,使用 println(cell.insuranceName.text)
,而不仅仅是 println(cell.insuranceName)
。
关于ios - 自定义 TableView 中的标签文本没有改变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32182762/