Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get indexPath from custom Tableview section header

I have created a custom View and added it to the tableView section header.

 func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {

        if section == 2 {

            if (headerView == nil) {
                headerView = CustomHeaderSection(frame: CGRectMake(0,0,self.view.bounds.width,38))
            }
            headerView!.delegate = self

            if isExpandableCell {

                headerView!.arrowImage.transform = CGAffineTransformIdentity

            }else {

                headerView!.arrowImage.transform = CGAffineTransformMakeRotation(CGFloat(M_PI))

            }
            return headerView

        }

        return nil
    }

I have a button on the custom view that I have added on the tableview section. Now how will I get the indexPath when I click on it?

like image 562
Bhavuk Jain Avatar asked Nov 21 '22 08:11

Bhavuk Jain


1 Answers

Declare a section number variable in CustomHeader class and assign its value while instantiating inside viewForHeaderInSection().

Implement the target button action inside the same class. So, on tap get self.section and pass it to ViewController.

void onButtonTap (id sender)
        {
            UIButton button = (UIButton)sender;

        this.sectionHeaderViewDelegate.buttonTapped (this.section);

        }
like image 89
Saurav Avatar answered Nov 22 '22 22:11

Saurav