开发者

is therea method like did select section in table view

开发者 https://www.devze.com 2023-01-07 17:53 出处:网络
i want to show data of section in a separate view if user touches that pa开发者_运维知识库rticular section..

i want to show data of section in a separate view if user touches that pa开发者_运维知识库rticular section.. can any body tell me how to do that?


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;


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


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)...


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

0

精彩评论

暂无评论...
验证码 换一张
取 消