Question

I do not understand why my cell.detailTextLabel.text is null.

static NSString *CellIdentifier = @"Cell";
//UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyId];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    /*[[NSBundle mainBundle] loadNibNamed:@"CellTest2" owner:self options:nil];
    cell = mealPlanCell;*/
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
    //self.mealPlanCell = nil;
}

cell.detailTextLabel.text = @"Test";

It will let me set the cell.textLabel.text to a value but not the detail one.

Was it helpful?

Solution

I figured out the reason if you leave

if(cell == nil){...}

around the cell = [[[UITableViewCell alloc]...

then the cells will not re render and thus will not update the style and or details so if you remove the if() then this will allow you to re render each cell in the table view if you are changing style back and forth. This is not a good thing to remove though if you think about it cause then it is going to low the tables "speed" which probably wont be noticeable but it is something to consider looking into as a possible issue. This is not what I did to solve the problem personally cause I choose to take a different approach but it is something that worked when I tried.

OTHER TIPS

I had same problem: UITableViewCell initWithStyle:UITableViewCellStyleSubtitle is not working

For those that search and find this question... and have same problem as me, where you are using a prototype cell and the style is not defined correctly in the storyboard.

If your rowHeight is not tall enough, the cell.detailTextLabel.text won't be visible even if the cell.textLabel.text is visible. A rowHeight of 22 seems to be the minimum with the default font.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top