Search code examples
objective-cuitableviewdynamicios5

iOS 5 XCODE 4.3.2 Can a dynamic prototyped tableview use groups?


I'm using storyboard and have a UITableView with dynamically prototyped cells. Now I was trying to make it grouped however every tutorial I can find only does grouping on static cells. When I select static I do see the 'sections' but not with dynamic. Is there an easy way to make my dynamic cells grouped?

Thanks,

Rob


Solution

  • You need to set the Grouped style on the table view.

    In storyboard select the table view by clicking on the part of the image that says prototype or in the left hand menu. There is style drop down box where you need to select Grouped.

    Assuming you have your view set up correctly, setting multiple sections and adding the cells to the correct selection you will start seeing the cells grouped as they are with static cells.

    You set the header of the section in the delegate to your UITableView by overriding the method below (If you are using a UITableViewController you set it there)

    - (NSString*)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
    {
        // set title of section here  
    }
    

    There is a similar method for the footer

    iOS 5 XCODE 4.3.2 Can a dynamic prototyped tableview use groups?