iOS - TableView - 点击按钮获取标题部分索引

Mru*_*rug 3 objective-c uitableview nsindexpath ios

我已经为UITableView实现了自定义标题部分.在Header的自定义视图中有一个按钮,我希望获得该部分的索引以点击该按钮的操作.

我可以尝试一下去

CustomHeader *view = (CustomHeader*)btnObject.superView;
Run Code Online (Sandbox Code Playgroud)

但是从这个headerView的实例中我怎样才能获得该部分的IndexPath或索引?

编辑: 我需要一些独立于标签的东西或任何类似于Cell的索引路径的东西,如下所示

-(NSIndexPath*)indexPathFromSenderView:(UIView*)view{

    CGPoint center= view.center;
    CGPoint rootViewPoint = [view.superview convertPoint:center toView:self.tblMainContainer];
    NSIndexPath *indexPath = [self.tblMainContainer indexPathForRowAtPoint:rootViewPoint];
    return indexPath;
}
Run Code Online (Sandbox Code Playgroud)

Vij*_*com 8

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{

    // create custom header here

    // set up a button method
    [yourButton addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];

    // set the button tag as section
    yourButton.tag = section;

    return yourCustomHeaderWithButton;
}


later


-(void)buttonAction:(id)sender{

    UIButton *clickedButton = (UIButton*)sender;
    NSLog(@"section : %i",clickedButton.tag);

}
Run Code Online (Sandbox Code Playgroud)