为什么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; } 

对于具有UITableViewCellStyleDefault样式的单元格,不显示detailTextLabel。 用UITableViewCellStyleSubtitle来初始化UITableViewCell,你应该看到你的detailTextLabel。

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

或者,如果您正在使用Interface Builder,请将Style单元格属性更改为Subtitle 。 🙂

在Interface Builder中设置样式单元属性。

我只想提一下UITableViewCell类引用中的措辞在这个问题上可能会有点混乱:

(在描述每种细胞types之后)

讨论在所有这些单元格样式中,较大的文本标签可通过textLabel属性访问,较小的通过detailTextLabel属性访问。

看起来这是说所有的单元格types都包含一个detailTextLabel,但是如果仔细阅读它们,它只是没有 detailTextLabel的默认types。

 iOS Swift : 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: UITableViewCell? = 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! }// end tableview cellForRowAtIndexPath 
Interesting Posts