UITableViewCell annexView在iOS9中未显示

and*_*ewz 0 uitableview uikit swift

试图在标签中的表格视图单元格的右侧以“ accessoryView”的形式显示数字,但该单元格仅显示单元格标签的文本。我究竟做错了什么?

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let item = items[indexPath.section][indexPath.row]
    let cell = UITableViewCell(style:.Default,reuseIdentifier:nil)        
    if let label = cell.textLabel {
        label.text = item.name
    }
    cell.selectionStyle     = .None

    let label = UILabel()
    label.textColor         = UIColor.blackColor()
    label.text              = String(item.count)
    label.textAlignment     = .Right
    cell.accessoryView      = label

    return cell
}
Run Code Online (Sandbox Code Playgroud)

All*_*len 5

我认为缺少UILabel的框架。

let label = UILabel(frame: CGRect(x: 0, y: 0, width: 45, height: 45))
label.textColor         = UIColor.blackColor()
label.text              = String("8")
label.textAlignment     = .Right
cell.accessoryView      = label
Run Code Online (Sandbox Code Playgroud)