I wish these were sufficient answers to my problem:
- In UITableView, cell.detailTextLabel.text isn't working… why?
- Why is detailTextLabel not visible?
- UITableView detailTextLabel - iphone development
- etc...
Unfortunately, either I am too thick-headed to see my solution in these comments, or they do not address my problem.
I am stubborn, in that I believe I should be able to display a detail text label without creating a custom UITableViewCell, all while creating my interface through the storyboard. The default storyboard prototype cell does not have an option for style. As well, no where in my code am I actually allocating this cell other than here; thus, I assume that it is being originally allocated in the storyboard to a default style that does not use detail text labels.
When I use the following code to populate cells, my detailTextLabel does not appear:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
NSLog(@"This is never called!");
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
// Configure the cell...
switch(indexPath.section) {
case 0: // boring cell
cell.textLabel.text = [NSString stringWithFormat:@"Default label"];
cell.textLabel.textAlignment = UITextAlignmentCenter;
break;
case 1: // loading cells based on contents of core data
{
// get some data from previously retrieved core data objects
NSManagedObject *rowObj = [myObjects objectAtIndex:[indexPath row]];
NSDate *someDate = (NSDate*)[rowObj valueForKey:@"timeStarted"];
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setTimeStyle:NSDateFormatterNoStyle];
[formatter setDateStyle:NSDateFormatterMediumStyle];
NSString *stringFromDate = [formatter stringFromDate: someDate];
// we have the fields ready; populate the cell
NSLog(@"This prints a valid date:%@", stringFromDate);
// this, also, displays just fine
cell.textLabel.text = [NSString stringWithFormat:@"Default text"];
// this does not appear
cell.detailTextLabel.text = stringFromDate;
break;
}
default:
break;
}
return cell;
}
I apologize in advance if this has been addressed elsewhere and my search-fu is lacking, or if there is a discussion of UITableViewCells and storyboards related to detail text label cell styles, but I have not seen them in my searches.
Specifically, what do I need to change in my code to set the style to use a detail text label while still using non-custom prototype UITableViewCells and keeping my storyboard intact?
Lastly, and this may be completely unrelated (please ignore if it is), if I generate many rows such that I can scroll down my table, all my rows appear fine other than there are a few (depending on how fast I scroll) that appear differently than the rest (text alignment). That is to say, as I understand it, I am seeing new cells being allocated/initialized without the same default settings I've specified in the storyboard. Note, the initWithStyle code below is still never called. If I am understanding this correctly, something is going on behind the scenes creating new cells, and I would like to know where so I can set the style preference. But again, if this is a symptom to an unrelated problem, please ignore, and I can post another question if it persists.
Sorry for the wall of text.