0

I have designed a cell in storyboard, then created a custom UITableViewCell subclass (BasicCell) and assigned it to it. Also set the proper identifiers. I created outlets of the custom cell in that class. Then in my UITableViewController subclass (where I have two types of prototype cells), the cells content won't show up. What am I doing wrong?

BasicCell.h

@interface BasicCell : UITableViewCell

@property (strong, nonatomic) IBOutlet UILabel *scorevalue;

@property (strong, nonatomic) IBOutlet UILabel *avgvalue;

@property (strong, nonatomic) IBOutlet UILabel *rankvalue;

@property (strong, nonatomic) IBOutlet UILabel *scorelabel;
@property (strong, nonatomic) IBOutlet UILabel *categorylabel;

@property (strong, nonatomic) IBOutlet UILabel *ranklabel;

@end

TableViewController.m

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
     static NSString *CellIdentifierBasic = @"basic";
     static NSString *CellIdentifierDetailed = @"detailed";

    UITableViewCell *cell;

    if(indexPath.row==0){
        // Create first cell

        cell = [[BasicCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifierBasic];


    }

    else{

        // Create all others

        cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifierDetailed forIndexPath:indexPath];
    }


    // Configure the cell...

    switch ([indexPath row])
    {
        case 0:
        {

            BasicCell *basicCell = (BasicCell *)cell;

            basicCell.scorelabel.text = @"test";
            basicCell.categorylabel.text = @"test";
            basicCell.ranklabel.text = @"test";

            basicCell.scorevalue.text = @"test";
            basicCell.avgvalue.text = @"test";
            basicCell.rankvalue.text = @"test";



        }
    }
user3211165
  • 225
  • 1
  • 3
  • 14

1 Answers1

1

In your storyboard,

  1. Create two prototype cell.
  2. Change one of your prototype cell's custom class. Set it BasicCell.
  3. Make sure that you set appropriate cell identifier for each type of cell.
  4. Don't alloc init if it's indexPath.row == 0 but dequeue with appropriate identifier.

It should work.

Note: You should declare your IBOutlets as weak not as strong. Cell's view has already strong pointer to them. You don't have to own them.

limon
  • 3,222
  • 5
  • 35
  • 52