Почему detailTextLabel не отображается?
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;
}
Ответы
Ответ 1
detailTextLabel
не отображается для cells
со стилем UITableViewCellStyleDefault
. init
в UITableViewCell
с UITableViewCellStyleSubtitle
вместо и вы должны увидеть detailTextLabel
.
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
Ответ 2
Или, если вы используете Interface Builder, измените свойство ячейки Style
на Subtitle
.:)
![Свойство ячейки стиля в Interface Builder.]()
Ответ 3
Я просто хочу упомянуть, что формулировка в ссылке класса UITableViewCell может быть немного запутанной по этой проблеме:
(После описания каждого типа ячейки)
" Обсуждение
Во всех этих стилях ячеек больше текстовых меток можно получить через свойство textLabel, а меньшее - через свойство detailTextLabel. "
Может показаться, что он говорит, что все типы ячеек содержат detailTextLabel, но если вы внимательно их просматриваете, то только тип по умолчанию, который имеет не, имеет detailTextLabel.
Ответ 4
Я использовал это, и это сработало для меня:
// 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!
}
Ответ 5
Чтобы решить это программно:
let cell = UITableViewCell(style: .subtitle, reuseIdentifier: "identifier")