waffles
waffles

Reputation: 37

Using Multiple UITableViewCells for one tableView

I am unsure if I'm setting up the UITableView the right way when using multiple custom cell views. I seem to have my table working however, i think the reuse of cells makes the first cells you see once you load the view the same size as the very first cell which should be the only cell thats double in size. Once I scroll passed them and back up they go to the size thats set for them.

Is there a right way of doing this? I've looked through other forms and tried their ways but this is the closed I've gotten it to work with just that one flaw.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{    
    static NSString *CellIdentifier1 = @"profileCell";
    static NSString *CellIdentifier2 = @"profileCells";

    if (indexPath.section == 0) {
        PFProfileTableCellView * cell = (PFProfileTableCellView *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier1];

        //only one row in this section
        return cell;

    } else{
        PFWallPostTableViewCell * cell = (PFWallPostTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier2];


        return cell;
    }
}

Last cell is the right size

Upvotes: 1

Views: 97

Answers (1)

Roger
Roger

Reputation: 208

Use this UITableView delegate method - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath; and return row height according to the sections of your tableview like the example below

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {

    if (indexPath.section == 0) {
        return 100.0;
    }
    return 50.0;
}

Upvotes: 1

Related Questions