Ulaş Sancak
Ulaş Sancak

Reputation: 907

Adding subtitle style to Table View Cell in XCode 4.3.3

I have a problem which makes me crazy. I think it is very easy to solve but I could not figure it out. I made a simple table view which has cells according two arrays. One is for main text in a cell, the other one is for subtitles in a cell. But the problem is When I make my cells with subtitle style, I can't see them when I run the application. Here is my code:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if ( cell == nil){
    cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
    }
    cell.textLabel.text = [hop objectAtIndex:indexPath.row];
    cell.detailTextLabel.text = [hop2 objectAtIndex:indexPath.row];

    return cell;
}

When I debugging I realize that when the program reaches the if block, it does not go into block. Which means "cell" is not nil at that moment. Question is why is that happening and how can I solve this? All your help will be appreciated.

Upvotes: 0

Views: 2094

Answers (2)

Senthilkumar
Senthilkumar

Reputation: 2481

Check your Array data.I think you not properly insert into array. Otherwise you are not initialize array

Upvotes: 0

dasdom
dasdom

Reputation: 14063

I assume you are using iOS5 and storyboards. Then dequeueReusableCellWithIdentifier: gives a valid cell back even if there isn't one in the reuse stack. Try to edit you cell in storyboard.

This stackoverflow question should help you to understand what happens.

Upvotes: 1

Related Questions