Почему detailTextLabel не виден? - PullRequest
54 голосов
/ 04 марта 2011

detailTextLabel не видно (код ниже). Ты можешь сказать мне, почему?

 // Customize the appearance of table view cells.
 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}

// Configure the cell...

NSString *cellValue = [myListArray objectAtIndex:indexPath.row];
cell.textLabel.text = cellValue;

cell.detailTextLabel.text = @"Hello "; // This is not visible
cell.image = [myListArrayImages objectAtIndex:indexPath.row];

return cell;
}

Ответы [ 4 ]

126 голосов
/ 11 марта 2011

detailTextLabel не отображается для cells со стилем UITableViewCellStyleDefault. init UITableViewCell с UITableViewCellStyleSubtitle вместо этого, и вы должны увидеть свой detailTextLabel.

cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
24 голосов
/ 24 июля 2016

Или, если вы используете Interface Builder, измените свойство ячейки Style на Subtitle. :)

Style cell property in Interface Builder.

0 голосов
/ 21 марта 2015

Я использовал это, и это сработало для меня:

// 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!
}
0 голосов
/ 01 ноября 2013

Я просто хочу упомянуть, что формулировка в ссылке на класс UITableViewCell может немного запутать эту проблему:

(После описания каждого типа ячеек)

« Обсуждение Во всех этих стилях ячеек доступ к большим текстовым меткам осуществляется через свойство textLabel, а для меньших - через свойство detailTextLabel. "

Может показаться, что все типов ячеек включают в себя detailTextLabel, но если вы внимательно прочитаете их, это будет только тип по умолчанию, который не имеет detailTextLabel.

...