mirror of
https://github.com/zhigang1992/ProMotion.git
synced 2026-06-03 19:45:10 +08:00
Abstract closest_parent into the viewhelper class.
This commit is contained in:
@@ -69,5 +69,14 @@ module ProMotion
|
||||
height
|
||||
end
|
||||
|
||||
def closest_parent(type)
|
||||
# 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? type
|
||||
this_view = this_view.superview
|
||||
end
|
||||
nil # this view is not within a tableView
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -47,7 +47,7 @@ module ProMotion
|
||||
|
||||
if data_cell[:accessory] == :switch
|
||||
switch_view = UISwitch.alloc.initWithFrame(CGRectZero)
|
||||
switch_view.addTarget(cell_table_view, action: "accessory_toggled_switch:", forControlEvents:UIControlEventValueChanged)
|
||||
switch_view.addTarget(self.closest_parent(UITableView), action: "accessory_toggled_switch:", forControlEvents:UIControlEventValueChanged)
|
||||
switch_view.on = true if data_cell[:accessory_checked]
|
||||
self.accessoryView = switch_view
|
||||
elsif data_cell[:accessory]
|
||||
@@ -154,17 +154,5 @@ 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
|
||||
|
||||
Reference in New Issue
Block a user