Reputation: 2187
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?
Upvotes: 5
Views: 3725
Reputation: 538
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);
}
Upvotes: 1
Reputation: 1
On your function you can add a tag id to the button to be the same as the indexPath
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("FoldingCell", forIndexPath: indexPath) as! myTableViewCell
...
cell.myButton.tag = indexPath.row
...
}
Upvotes: 0
Reputation: 4198
You can assign the tag
property of your section header view to number of section inside tableView(tableView: UITableView, viewForHeaderInSection section: Int)
method.
Upvotes: -1