sudo rm -rf
sudo rm -rf

Reputation: 29524

UITableViewCellStyleSubtitle not showing correctly

I'm trying to display some text as a subtitle in my tableView.

Here's my code for part of the tableView:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *SimpleTableIdentifier = @"SimpleTableIdentifier";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:SimpleTableIdentifier];

    if (cell == nil)
    {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:SimpleTableIdentifier] autorelease]; } //did the subtitle style

        NSUInteger row = [indexPath row];
        cell.textLabel.text = [listData objectAtIndex:row];
        return cell;

        cell.detailTextLabel.text = @"Hello there";  //This is not displaying...
    }
}

Is there any reason why I'm not seeing the subtitle text when I run?

Upvotes: 0

Views: 8854

Answers (1)

Sorig
Sorig

Reputation: 1211

return cell;

cell.detailTextLabel.text = @"Hello there";  //This is not displaying...

You set the detailTextLabel after you return the cell. When you return the cell you leave the method. Therefore the last line of code isn't run.

Upvotes: 19

Related Questions