I have a tableView dynamically populated with custom cells in several sections.
In my CustomCell class I have an @IBAction for a custom checkbox button in the cell. Is there a way to get the section number of the sender button in the IBAction function?
Something like:
@IBAction func checkboxButton(sender: CheckBox) {
//Change Button state
if sender.isChecked == true { sender.isChecked = false }
else { sender.isChecked = true }
//Get section number of clicked button
var sectionNumber = ???????
}
You can easily find the row by calculating the position of the sender and finding the row at that position in the UITableView
var position: CGPoint = sender.convertPoint(CGPointZero, toView: self.tableView)
if let indexPath = self.tableView.indexPathForRowAtPoint(position)
{
let section = indexPath.section
let row = indexPath.row
}
This is how Apple does it in the Accessory sample. https://developer.apple.com/library/ios/samplecode/Accessory/Listings/AccessoryViewController_m.html#//apple_ref/doc/uid/DTS40008066-AccessoryViewController_m-DontLinkElementID_4
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With