From bc63572b85ba836ad4fe3ae5cd9746c8dbd99aa9 Mon Sep 17 00:00:00 2001 From: Mark Rickert Date: Thu, 6 Jun 2013 09:53:36 -0400 Subject: [PATCH] Find the cell's table view and set the action to target the tableview instead of self. --- .../screens/_tables/table_view_cell_module.rb | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/ProMotion/screens/_tables/table_view_cell_module.rb b/lib/ProMotion/screens/_tables/table_view_cell_module.rb index 00b47c1..60d66cf 100644 --- a/lib/ProMotion/screens/_tables/table_view_cell_module.rb +++ b/lib/ProMotion/screens/_tables/table_view_cell_module.rb @@ -46,7 +46,7 @@ module ProMotion self.accessoryView.autoresizingMask = UIViewAutoresizingFlexibleWidth elsif data_cell[:accessory] && data_cell[:accessory] == :switch switch_view = UISwitch.alloc.initWithFrame(CGRectZero) - switch_view.addTarget(self, action: "accessory_toggled_switch:", forControlEvents:UIControlEventValueChanged) + switch_view.addTarget(cell_table_view, action: "accessory_toggled_switch:", forControlEvents:UIControlEventValueChanged) switch_view.on = true if data_cell[:accessory_checked] self.accessoryView = switch_view end @@ -150,5 +150,17 @@ module ProMotion def set_selection_style self.selectionStyle = UITableViewCellSelectionStyleNone if data_cell[:no_select] end + + def cell_table_view + @cell_tableview ||= begin + # iterate up the view hierarchy to find the table containing this cell/view + this_view = self.superview + while this_view != nil do + return this_view if this_view.is_a? UITableView + this_view = this_view.superview + end + nil # this view is not within a tableView + end + end end end