cell.detailTextLabel.text不工作......为什么

use*_*859 33 iphone xcode uitableview

使用以下代码我得到text.label但不是detailTextLabel.text.NSLog正确显示.

cell.textLabel.text = [eventLabels objectAtIndex:indexPath.row];  
cell.detailTextLabel.text = [eventFields objectAtIndex:indexPath.row]];  

NSLog(@"%@", [eventFields objectAtIndex:indexPath.row]);  
Run Code Online (Sandbox Code Playgroud)

我也试过......

cell.detailTextLabel.text = [NSString stringWithFormat:@"%@", [eventFields objectAtIndex:indexPath.row]];     
Run Code Online (Sandbox Code Playgroud)

我之前没有遇到任何问题.有什么建议?

约翰

jbr*_*nan 85

确保你使用适当的UITableViewCellStyle(任何东西,但UITableViewCellStyleDefault应该这样工作).初始化时指定单元格的样式.

  • user278859:如果约翰回答了你的问题,那么接受他的回答.如果你不接受正确的答案,有什么用? (10认同)

小智 24

- (UITableViewCell *)tableView:(UITableView *)tableView 
         cellForRowAtIndexPath:(NSIndexPath *)indexPath {

if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle 
                                   reuseIdentifier:CellIdentifier] autorelease];
}
Run Code Online (Sandbox Code Playgroud)

请记得更改为UITableViewCellStyleSubtitle