最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

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

Swift crifan 4200浏览 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,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
84 queries in 0.194 seconds, using 22.10MB memory