I’m adding two buttons to my UITableView section Headers. The button action method needs to know the section number, but the only argument it receives is the button itself. Can the section number be got from some superview of the button?
I know I could embed the section number in the button somehow (maybe by using the tag field), I’d prefer not to do it that way if possible.
This code does the job of getting the index path of a button in a cell:
NSIndexPath *indexPath = [self.tableView indexPathForCell: (UITableViewCell *)sender.superview.superview]
I’m looking for something equivalent for getting the section number from a button in a section header.
While allocating the buttons for each section, set a tag like
This way when your button action is invoked, you can check for the tag using