Search code examples
iosuitableviewcell-formatting

cell.detailTextLabel.text is NULL


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.


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.