1

I want to have one custom cell (the first one) a different height to the others. I've done a few things to do this but every cell is the same height:

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row == 0) {
    return 150;
}
else {
    return 60;
}
}

and

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *identifier;

if (indexPath.row == 0) {
    identifier = @"ProfilePictureCell";
}
else if (indexPath.row == 1) {
    identifier = @"OtherCell";
}

UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:identifier];

I can't figure out why these aren't working.. Thanks!

EDIT: Here is the code for the cell:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *identifier;

if (indexPath.row == 0) {
    identifier = @"ProfilePictureCell";
}
else if (indexPath.row > 0) {
    identifier = @"1";
}
UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:identifier];

if (cell == nil) {

    NSArray *nibArray = [[NSBundle mainBundle] loadNibNamed:@"ProfilePictureCell" owner:self options:nil];
    cell = [nibArray objectAtIndex:0];
}

cell.imageView.image = [UIImage imageNamed:[self.foodImageArray objectAtIndex:indexPath.row]];

return cell;

}

This code displays the image in the first cell, which is great, but every other cell is the same size. Thanks

  • 1
    Try putting a breakpoint in the height for row method and see the control flow – rounak Jul 05 '15 at 11:03
  • Another thing to look at: You might want to change `else if (indexPath.row == 1)` to `else if (indexPath.row > 0)`. Here's a post you might find helpful. http://stackoverflow.com/questions/494562/setting-custom-uitableviewcells-height – Adrian Jul 05 '15 at 14:39
  • could you post the other methods from the tableViewDelegate? maybe you have always `indexPath.row = 0` if you grouped them in different sections, instead of all in one section – Catalina T. Jul 05 '15 at 17:45
  • where are you defining the cells? all of the in nib files? Your `cellForRowAtIndexPath` does not look correct. Could you also post `numberOfRowsInSection` and `numberOfSectionsInTableView`? I think that's where the error might be. – Catalina T. Jul 06 '15 at 13:25

0 Answers0