如何知道UITableView行号我有一个UITableViewCell带着UISwitch作为每个单元格的辅助视图。当我在单元格中更改开关的值时,如何知道开关在哪一行?我需要切换值更改事件中的行号。
3 回答
ibeautiful
TA贡献1993条经验 获得超5个赞
tag
tableView:cellForRowAtIndexPath:
superview
UISwitch
UITableViewCell
UITableView
static NSIndexPath *indexPathForView(UIView *view) { while (view && ![view isKindOfClass:[UITableViewCell class]]) view = view.superview; if (!view) return nil; UITableViewCell *cell = (UITableViewCell *)view; while (view && ![view isKindOfClass:[UITableView class]]) view = view.superview; if (!view) return nil; UITableView *tableView = (UITableView *)view; return [tableView indexPathForCell:cell];}
tableView:cellForRowAtIndexPath:
.
慕雪6442864
TA贡献1812条经验 获得超5个赞
tag
extension Int { public init(indexPath: IndexPath) { var marshalledInt: UInt32 = 0xffffffff let rowPiece = UInt16(indexPath.row) let sectionPiece = UInt16(indexPath.section) marshalledInt = marshalledInt & (UInt32(rowPiece) << 16) marshalledInt = marshalledInt + UInt32(sectionPiece) self.init(bitPattern: UInt(marshalledInt)) } var indexPathRepresentation: IndexPath { let section = self & 0x0000ffff let pattern: UInt32 = 0xffff0000 let row = (UInt32(self) & pattern) >> 16 return IndexPath(row: Int(row), section: Int(section)) }}
tableView(_:, cellForRowAt:)
cell.yourSwitch.tag = Int(indexPath: indexPath)
func didToogle(sender: UISwitch){ print(sender.tag.indexPathRepresentation)}
{section area length}{all remaining}[4 BITS: section area length - 1]
- 3 回答
- 0 关注
- 471 浏览
添加回答
举报
0/150
提交
取消