views:

255

answers:

1

I want to create a tableview like this. All sections have custom section header views.

The first row of first section contains a custom row rest of the first section cell's are another custom cell. Though every section will contain different type of cells.

So what is the best approach to achieve this while managing the speed of tableview? Currently I'm using custom cells using interface builder. Is there a way that I could add different things on different sections on cells?

+2  A: 

Try to keep as few types of cells as you can. If one type cell is similar to another but with one or two extra labels, just set it all up in the same cell and keep the labels empty on the cell that doesn't need them. That way they can be in the same reuse queue. If the cells are different enough you might need to have more queues. Just instantiate them with a different cellIdentifier and they will get added to the queue for that identifier.

eg.

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

    if(indexPath.row == 0) {
         cell = [tableView dequeueReusableCellWithIdentifier:@"firstRowCell"];

        if(!cell) {
            cell = [[UITableViewCell alloc] inittWithFrame:CGRectZero reuseIdentifier:@"firstRowCell"];
        }

        // -- first cell setup

    } else {
         cell = [tableView dequeueReusableCellWithIdentifier:@"genericRowCell"];

        if(!cell) {
            cell = [[UITableViewCell alloc] inittWithFrame:CGRectZero reuseIdentifier:@"genericRowCell"];
        }

        // -- generic cell setup
    }

    // -- common cell setup

    return cell;

}
monowerker
it seems your method will work.But what i do here is expandable sections.So i reload section when click on section header and reload the table.If i do not reload table the app is crashed.And when i scrolls down my IBCells behavesvery strange.I have a seperater set to clear color of tableview and i put a label of gray color in custom cell at bottom.But when i scrolls table the label color becoms white If i select the cell i can see gray label.I don't know why it becomes white when scrolling? Do you know anything about this?
Rahul Vyas
Sorry no, this is very hard to say anything about without seeing some code. You could add it to your original question.
monowerker