Why is detailTextLabel not visible?

一笑奈何 提交于 2019-11-28 06:41:27
Opsimath

The detailTextLabel is not displayed for cells with the UITableViewCellStyleDefault style. init the UITableViewCell with UITableViewCellStyleSubtitle instead and you should see your detailTextLabel.

cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];

Or if you are using Interface Builder, change the Style cell property to Subtitle. :)

I just want to mention that the wording in the UITableViewCell class reference can be a little bit confusing on this issue:

(After describing each cell type)

"Discussion In all these cell styles, the larger of the text labels is accessed via the textLabel property and the smaller via the detailTextLabel property."

It might seem that it's saying all of the cell types include a detailTextLabel, but if you carefully read through them it's only the default type that does not have a detailTextLabel.

Vinod Joshi

I have used this and it worked for me:

// programming mark ----- ----- ---- ----- ----- ---- ----- ----- ----

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let CellIdentifier: String = "CellIdentifier"

    var cell = tableView.dequeueReusableCellWithIdentifier(CellIdentifier) as? UITableViewCell

    if cell == nil {
        cell = UITableViewCell(style: UITableViewCellStyle.Value1, reuseIdentifier: CellIdentifier)
    }

    cell!.textLabel!.text = "Title"
    cell!.detailTextLabel!.text = "Value"

    return cell!
}

In order to solve it programmatically:

let cell = UITableViewCell(style: .subtitle, reuseIdentifier: "identifier")
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!