UITableViewController select header for section

后端 未结 4 970
盖世英雄少女心
盖世英雄少女心 2020-12-24 11:47

I have a UITableView with multiple sections. Each section has a section header (a custom view) is there an easy way to detect when someone selects the section h

4条回答
  •  孤城傲影
    2020-12-24 12:18

    This isn't radically different than @rckoenes answer, but it does provide a more orthodox way of handling events on views rather than using invisible buttons.

    I'd rather add a UITapGestureRecognizer to my header view instead of adding invisible buttons and resizing them:

    UITapGestureRecognizer *singleTapRecogniser = [[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleGesture:)] autorelease];
    [singleTapRecogniser setDelegate:self];
    singleTapRecogniser.numberOfTouchesRequired = 1;
    singleTapRecogniser.numberOfTapsRequired = 1;   
    [yourHeaderView addGestureRecognizer:singleTapRecogniser];
    

    and then:

    - (void) handleGesture:(UIGestureRecognizer *)gestureRecognizer;
    

    You can use gesture.view to see which was touched. Then do whatever you need to do to find out which header it was (tags, data array lookup... )

提交回复
热议问题