views:

25

answers:

4

i want to show data of section in a separate view if user touches that particular section.. can any body tell me how to do that?

A: 

Use -tableView:didSelectRowAtIndexPath: and just test the indexPath.section property, e.g.:

switch (indexPath.section) 
    case kFirstSection:
        [self doSomethingWithCustomViewForSection:kFirstSection];
        break;
    case kSecondSection:
        [self doSomethingWithCustomViewForSection:kSecondSection];
        break;
    ...
    default:
        break;
Alex Reynolds
A: 

You can use indexPath.section within the didSelectRowAtIndexPath: method to determine the section of the cell selected

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    NSLog(@"%i",indexPath.section);
}

The above will output to the console the section that the user has selected

James Raybould
A: 

heres what i used. basiaclly what they said but if you want to load ina detail view of some kind here:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {


DetailViewController *detail = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil];
detail.item =(MWFeedItem *)[items objectAtIndex:indexPath.row]; 
// ...
 // Pass the selected object to the new view controller.
 [self.navigationController pushViewController:detail animated:YES];
 [detail release];

[self.tableView deselectRowAtIndexPath:indexPath animated:YES];
}

note: MWFeedItem is one of my classes. you should use your own

Colby Bookout
A: 

If you mean that you want to catch the tap on the section header (the text that you return from tableView:titleForHeaderInSection:) then I'm afraid it's impossible...

You might use the tableView:viewForHeaderInSection: instead and add a transparent button on top of the text. You might also add a transparent text to this button that will hold the section index. This way you can point all the section header buttons to the same selector and in that selector you will have the section (the text of the button)...

Michael Kessler
You could create a button or custom view to insert via the delegate method `tableView:viewForHeaderInSection:`. This custom view/button can respond to taps.
Alex Reynolds
:) I have added exactly the same solution to my answer exactly in the same time with your comment...
Michael Kessler