UITableViewCell initWithStyle:UITableViewCellStyleSubtitle is not working

ios, uitableview

Solution

When using storyboards and prototype cells, a cell is always returned from the dequeue method (assuming a prototype with that identifier exists). This means you never get into the `(cell == nil)` block.

In your case the prototype cell is not defined in the storyboard with the subtitle style, so a subtitled cell is never used, and the detail text label does not exist. Change the prototype in the storyboard to have the subtitle style.

Problem

I'm having an issue in trying to display info in a cell, one on the left and one on the right. I'm aware using `initWithStyle` with `UITableViewCellStyleSubtitle`. I use this but it doesn't seem to work. Here is some sample code: ``` - (UITableViewCell *)tableView:(UITableView *)ltableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Account Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:Cellidentifier]; } Accounts *account = [self.fetchedResultsController objectAtIndexPath]; cell.textLabel.text = account.name; cell.detailTextLabel.text = @"Price"; return cell; } ``` I can display cell.textLabel.text just fine, however I cannot get the simple "Price" to be displayed. I've tried different things, such as setting the font size of `cell.detailTextLabel`. I've also tried `UITableViewCellStyleValue1` as some had suggested in older posts. Threw NSLog after setting to "Price", shows cell.detailTextLabel as null. Not sure what I'm doing wrong. Edit: I found this: cell.detailTextLabel.text is NULL If I remove `if (cell == nil)` it works... That check should be in place, so how do you make it work when using the different styles?

Original source