Get section number in custom cell button action

后端 未结 5 1263
北恋
北恋 2021-01-13 23:42

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.

5条回答
  •  梦谈多话
    2021-01-14 00:11

    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

提交回复
热议问题