ios - 自定义 TableView 中的标签文本没有改变

标签 ios swift uitableview uilabel

我使用下面的代码更改我的自定义 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/

相关文章:

ios - 如何从 GameScene.swift 中关闭 ViewController?

ios - 使用 Firebase 数据填充 Collection View

swift - 在 swift 中使用 GCD 的竞争条件

ios - Swift 静态数组 - 正在释放的指针未分配

ios - 使用文件作为 UITableView 的数据源

ios - 关于 iOS 辅助功能。如何将焦点转移到 pickerView

objective-c - RestKit 使用 setObjectMapping 从核心数据中删除旧数据

ios - TableView 不重新加载

ios - 如何动态调整TableView Cell Height和TableView Height的大小

objective-c - 如果cell == nil,可以安全删除uitableview吗?