すべての行に UISwitch を持つ UITableView myTable があります。
switchChanged メソッドでスイッチが変更されたテーブルの行番号を見つけるにはどうすればよいですか?
- (void) switchChanged:(id)sender {
UISwitch* mySwitch = sender;
NSLog( @"%d", mySwitch.on );
}
ありがとうございました
すべての行に UISwitch を持つ UITableView myTable があります。
switchChanged メソッドでスイッチが変更されたテーブルの行番号を見つけるにはどうすればよいですか?
- (void) switchChanged:(id)sender {
UISwitch* mySwitch = sender;
NSLog( @"%d", mySwitch.on );
}
ありがとうございました
One suggestion could be to use the tag.
When you setup the cell with the switch in cellForRowAIndexPath:
you can set the switch tag to the row value. That way you can read out the tag again and get the row and item...
セクションが 1 つだけ (またはその方法を使用するスイッチを含むセクションが 1 つだけ) ある場合は、スイッチのtag
プロパティに行番号を格納できます。または、妥当な数のセクションと行に制限する場合は、タグ整数の上位 N ビットにセクション番号を格納し、下位 M ビットに行番号を格納できます (最良の結果を得るには N+M < 32)。
またはsuperview
、UITableViewCell が見つかるまでスイッチから使用し (を使用してテストisKindOfClass:
)、indexPathForCell:
テーブル ビューで使用してインデックス パスを見つけることができます。
または、UISwitch をサブクラス化して、インデックス パスを格納するプロパティを持たせることもできます。
objc_setAssociatedObject
または、インデックス パスをスイッチに関連付けるために使用できます。