テーブルビューセルにスワイプジェスチャを追加するにはどうすればよいですか?テーブルビューでカスタムセルを使用していますが、テーブルからその行を削除する必要があるので、テーブルビューでこのスワイプジェスチャを使用する方法を教えてください。
4471 次
2 に答える
1
他のビューとまったく同じです。このコードを、カスタムセルのinitまたはUITableViewDataSourceデリゲートのcellForRowAtIndexPathメソッドのいずれかに挿入します。
UISwipeGestureRecognizer *recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:myTableViewController action:@selector(removeCell:)];
recognizer.direction = UISwipeGestureRecognizerDirectionLeft;
recognizer.numberOfTouchesRequired = 1;
[self addGestureRecognizer:recognizer];
[recognizer release];
于 2011-09-14T13:19:30.933 に答える
0
2つのデリゲートメソッドを実装する必要があります。
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
return YES;
}
コードの編集または削除を実行する必要があるその他の方法。
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
//write delete code.
[arry removeObjectAtIndex:indexPath.row];
[Table reloadData];
}
}
于 2011-09-14T13:31:26.840 に答える