You are missing the fact that you can use the delegate design template here.
Create a protocol that informs delegates about the state change in your checkbox (imageView):
enum CheckboxState: Int { case .Checked = 1 case .Unchecked = 0 } protocol MyTableViewCellDelegate { func tableViewCell(tableViewCell: MyTableViewCell, didChangeCheckboxToState state: CheckboxState) }
And if you have a subclass of UITableViewCell :
class MyTableViewCell: UITableViewCell { var delegate: MyTableViewCellDelegate? func viewDidLoad() {
And in a subclass of UITableViewController :
class MyTableViewController: UITableViewController, MyTableViewCellDelegate { // Other methods here (viewDidLoad, viewDidAppear, etc)... override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) { var cell = tableView.dequeueReusableCellWithIdentifier("YourIdentifier", forIndexPath: indexPath) as MyTableViewCell // Other cell setup here... // Assign this view controller as our MyTableViewCellDelegate cell.delegate = self return cell } override func tableViewCell(tableViewCell: MyTableViewCell, didChangeCheckboxToState state: CheckboxState) { // You can now access your table view cell here as tableViewCell } }
Hope this helps!
source share