Мне нужно пронести по ячейке и вместо того, чтобы показывать красную кнопку «Удалить», показать AlertView, спрашивая, действительно ли пользователь хочет удалить.Удалить UITableViewCell без кнопки удаления?
Любая помощь приветствуется!
Мне нужно пронести по ячейке и вместо того, чтобы показывать красную кнопку «Удалить», показать AlertView, спрашивая, действительно ли пользователь хочет удалить.Удалить UITableViewCell без кнопки удаления?
Любая помощь приветствуется!
ли Подобно этому,
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
UIAlertView *Alert = [[UIAlertView alloc] initWithTitle:@"" message:@"Are you sure to commit with its action" delegate:self cancelButtonTitle:CKString(@"NO") otherButtonTitles:CKString(@"YES"),nil];
[Alert show];
Alert.tag=indexPath.row+1;
Alert.delegate=self;
[Alert release];
return UITableViewCellAccessoryNone;
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
}
В AlertView делегатом
-(void) alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
int indexPathRow=alertView.tag-1;
if(buttonIndex==1)
{
//// Yes condition
} else {
///// No condition
}
}
Вы можете добавить gestureRecognizer в камеру
UISwipeGestureRecognizer *recognizer =[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(removeCell:)];
recognizer.direction = UISwipeGestureRecognizerDirectionRight;
[cell addGestureRecognizer:recognizer];
[recognizer release];
, а затем в методе removeCell
- (void)handleSwipeFrom:(UISwipeGestureRecognizer *)recognizer
{
UITableViewCell *cell = (UITableViewCell*)[recognizer view];
NSIndexPath* pathOfTheCell = [viewListTable indexPathForCell:cell];
NSInteger rowOfTheCell = [pathOfTheCell row];
NSInteger sectionOftheCell = [pathOfTheCell section];
UIAlertView *confirmationAlert = [[UIAlertView alloc]initWithTitle:@"Confirm" message:@"Are you sure you want to Delete this list?" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Delete", nil];
[confirmationAlert show];
confirmationAlert.delegate = self;
[confirmationAlert release];
}
Добавить UISwipeGestureRecognizer
в Cell
UISwipeGestureRecognizer *gesture;
gesture = [[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom:)] autorelease];
gesture.direction = UISwipeGestureRecognizerDirectionLeft;
[cell addGestureRecognizer:gesture];
gesture = [[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom:)] autorelease];
gesture.direction = UISwipeGestureRecognizerDirectionRight;
[cell addGestureRecognizer:gesture];
А внутри метода селектор строки для Подтвердить Удалить
- (void)handleSwipeFrom:(UISwipeGestureRecognizer *)recognizer
{
//Use recognizer.direction to check left/right swipe if needed
//Prompt Alert
CGPoint location = [recognizer locationInView:tableView];
NSIndexPath *swipedIndexPath = [tableView indexPathForRowAtPoint:location];
UITableViewCell *swipedCell = [tableView cellForRowAtIndexPath:swipedIndexPath];
}
Мне нужно иметь доступ к indexPath ячейки. – ranjha
Пожалуйста, ознакомьтесь с обновленным ответом –
В Alertview делегатом
if (alertView.tag == index)
{
if (buttonIndex == 1)
{
[yourArray removeObjectAtIndex:alertView.tag-1];
[yourTable reloadData];
}
}
Еще есть такая же проблема, как получить доступ к indexPath удалить строки в делегате alertView? – ranjha
Посмотрите, как все сказали мне добавить GestureRecognizer. – ranjha
извините за неудобства .... – Venkat