プログラムで UITableView を作成し、そのセル アクセサリ ビューに UISwitch を追加しました。
これは、メソッドのセル アクセサリ ビューでの UISwitch のコードですcellForRowAtIndexPath
。
UISwitch *accessorySwitch = [[UISwitch alloc]initWithFrame:CGRectZero];
[accessorySwitch setOn:NO animated:YES];
[accessorySwitch addTarget:self action:@selector(changeSwitch:) forControlEvents:UIControlEventValueChanged];
cell.accessoryView = accessorySwitch;
ボタンがクリックされた後に呼び出されるメソッドです。
- (void)changeSwitch:(UISwitch *)sender{
UITableViewCell *cell = (UITableViewCell *)[sender superview];
NSIndexPath *indexPath = [self.filterTableView indexPathForCell:cell];
NSLog(@"%ld",(long)indexPath);
……………. My other code…….
}
iOS 6 ではインデックス パスの値を出力できますが、iOS 7 では nil を出力します。
iOS 7 に何か足りないものがありますか、それとも iOS 7 で indexPath を取得する別の方法があります
ありがとう、アルン。