我试图让一个字幕显示在我的表格视图的单元格中,但由于某种原因它没有出现。我将单元格的样式设置为 UITableViewCellStyleSubtitle,所以这不是问题。以下是相关代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
NMADRestaurant *restaurant = [self.restaurants objectAtIndex:indexPath.row];
cell.textLabel.text = [restaurant name];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
CLLocation *restaurantLocation = [restaurant location];
CLLocationDistance distance = [currentLocation distanceFromLocation:restaurantLocation];
NSString *distanceString = [NSString stringWithFormat:@"%.1f km",(distance/1000)];
cell.detailTextLabel.text = distanceString;
return cell;
}
如果我 NSLog distanceString,它会正确显示。但是当我 NSLog(@"Label %@",cell.detailTextLabel.text), "Label (null)" 是所有出现在日志中。