Question

In my app I have 3 categories(sections) and in each category I have 3 items(rows). I have implemented it by using grouped style UITableview.

But the way it is grouping does not suits my app flow.

How can I customise UITableview sections?

I actually want 3 blocks kind of sections and also I should be able to select the whole block not the individual sub-categories(i.e rows). New controller will present when the user selects the whole block. Is their any method like : -didSelectSectionAtIndexpath? So that whole action can be performed on the whole section?

Was it helpful?

Solution 2

Could you please elaborate a little on the question? What is it that you want to show once the Sections is touched?? a viewcontroller with the 3 items related to that section or something else??

OTHER TIPS

You can create custom header view as follows and in same way you can set footer as well

For Header

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
   UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, 18)];

 /* Create custom view to display section header... */

UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 5, tableView.frame.size.width, 18)];
[label setFont:[UIFont boldSystemFontOfSize:12]];
 NSString *string =[list objectAtIndex:section];

 /* Section header is in 0th index... */

[label setText:string];
[view addSubview:label];
[view setBackgroundColor:[UIColor colorWithRed:166/255.0 green:177/255.0 blue:186/255.0 alpha:1.0]]; //your background color...
return view;

}

For Footer

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section;   // custom view for footer. will be adjusted to default or specified footer height

You need to create both views in such a way that it will look same a whole (as per your UI requirement)

There is no didSelectSectionAtIndexpath method but you can do some improvisation. you can add a button to the entire header section and then present the new controller on this button click event.

Also call the same new controller on the didselectrowatindexpath.

Now set cell.selectionStyle = UITableViewCellSelectionStyleNone; in cellForRowAtIndexPath. This will give the user the impression that he is actually selection the entire block.

You will also have to create the UI smarlty so that the header and row look like one section.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top