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;
}发布于 2011-03-11 09:27:05
对于具有UITableViewCellStyleDefault样式的cells,不显示detailTextLabel。改为使用UITableViewCellStyleSubtitle init UITableViewCell,您应该会看到您的detailTextLabel。
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];发布于 2016-07-24 08:43:24
或者,如果使用的是接口生成器,请将Style单元格属性更改为Subtitle。:)

发布于 2020-05-06 19:34:26
Swift 5
您可以在cellForRowAt方法内部启用此功能
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
var cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
cell = UITableViewCell(style: .subtitle, reuseIdentifier: "cell")
cell.textLabel?.text = qus[indexPath.row]
cell.detailTextLabel?.text = ans[indexPath.row]
return cell
}https://stackoverflow.com/questions/5190648
复制相似问题