代码:
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: