I have a UITableViewCell
with UISwitch
as accessoryview of each cell. When I change the value of the switch in a cell, how can I know in which row the switch is? I need the row number in the switch value changed event.
相关问题
- CALayer - backgroundColor flipped?
- Core Data lightweight migration crashes after App
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- State preservation and restoration strategies with
相关文章
- 现在使用swift开发ios应用好还是swift?
- UITableView dragging distance with UIRefreshContro
- Could I create “Call” button in HTML 5 IPhone appl
- TCC __TCCAccessRequest_block_invoke
- Where does a host app handle NSExtensionContext#co
- Unable to process app at this time due to a genera
- Swift - hide pickerView after value selected
- Popover segue to static cell UITableView causes co
One more variant of using superView. Works like category for UIView.
i dont know about the multiple sections but i can give you for the one section...
from this you can get the row number and you can save it to the string....
If you set the
tag
property to the row number (as suggested by other answers), you have to update it every time intableView:cellForRowAtIndexPath:
(because a cell can be reused for different rows).Instead, when you need the row number, you can walk up the
superview
chain from theUISwitch
(or any other view) to theUITableViewCell
, and then to theUITableView
, and ask the table view for the index path of the cell:This doesn't require anything in
tableView:cellForRowAtIndexPath:
.Tags, subclasses, or view hierarchy navigation are too much work!. Do this in your action method:
Works with any type of view, multi section tables, whatever you can throw at it - as long as the origin of your sender is within the cell's frame (thanks rob!), which will usually be the case.
And here it is in a UITableView Swift extension: