最新消息:VPS服务器又从fzhost.net换回linode了,主题仍用朋友推荐的大前端D8

[已解决]swift的UITableViewCell的accessoryView不显示

Swift crifan 99浏览 0评论

代码:

        cell.accessoryType = UITableViewCellAccessoryType.None
        let accessoryViewFrame = CGRectMake(
            0,
            0,
            60,
            HeightFileTableViewCell)
        let updateTimeLabel = UILabel(frame: accessoryViewFrame)
        updateTimeLabel.text = curFileItem.updatedTime.toString("yy/MM/dd HH:mm:ss")
        updateTimeLabel.textColor = UIColor.grayColor()
        updateTimeLabel.font = UIFont.systemFontOfSize(13)
        updateTimeLabel.textAlignment = NSTextAlignment.Right
        cell.accessoryView?.frame = accessoryViewFrame
        cell.accessoryView?.addSubview(updateTimeLabel)
        //for debug
        updateTimeLabel.backgroundColor = UIColor.purpleColor()
        cell.accessoryView?.backgroundColor = UIColor.greenColor()

结果cell.accessoryView不显示。。。

swift uitableviewcell accessoryview not show

uitableview – iOS UiTableViewCell selective cells to show accessoryView – Stack Overflow

Swift tableView cell set accessory type – Stack Overflow

然后用代码:

        cell.accessoryType = UITableViewCellAccessoryType.None
        let accessoryViewFrame = CGRectMake(
            0,
            0,
            120,
            HeightFileTableViewCell)
        cell.accessoryView = UIView(frame: accessoryViewFrame)
       
        let updateTimeLabel = UILabel(frame: accessoryViewFrame)
        updateTimeLabel.text = curFileItem.updatedTime.toString("yy/MM/dd HH:mm:ss")
        updateTimeLabel.textColor = UIColor.grayColor()
        updateTimeLabel.font = UIFont.systemFontOfSize(13)
        updateTimeLabel.textAlignment = NSTextAlignment.Right
//        cell.accessoryView?.frame = accessoryViewFrame
        cell.accessoryView?.addSubview(updateTimeLabel)

即可显示accessory view:

转载请注明:在路上 » [已解决]swift的UITableViewCell的accessoryView不显示

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
17 queries in 0.247 seconds, using 9.74MB memory