我正在尝试为表格 View 中的单元格添加副标题。我正在尝试这段代码,但没有显示副标题。
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell=tableView.dequeueReusableCellWithIdentifier("topCell", forIndexPath: indexPath) as UITableViewCell
cell.textLabel?.text=listPerson[indexPath.row].name
cell.detailTextLabel?.text="test"
var personImage=UIImage(named: listPerson[indexPath.row].country)
cell.imageView?.image=personImage
return cell
}
我还想知道是否可以在单元格右侧添加另一张图片。
最佳答案
要在 detailTextLabel
中显示文本,您必须在 Interface Builder (⌥⌘4) 的属性检查器中将单元格的样式设置为 Subtitle
.
要在右边缘添加自定义图像,您可以以编程方式创建 UIImageView
实例,并将其作为 subview 添加到辅助 View 。
然而,使用提供 socket 的自定义单元类可能更合适。
关于ios - 使用 swift 自定义 TableViewCell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38201649/