2013-02-27 4 views
-1

Мне нужно пронести по ячейке и вместо того, чтобы показывать красную кнопку «Удалить», показать AlertView, спрашивая, действительно ли пользователь хочет удалить.Удалить UITableViewCell без кнопки удаления?

Любая помощь приветствуется!

ответ

0

ли Подобно этому,

- (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 
     } 

} 
+0

Еще есть такая же проблема, как получить доступ к indexPath удалить строки в делегате alertView? – ranjha

+0

Посмотрите, как все сказали мне добавить GestureRecognizer. – ranjha

+0

извините за неудобства .... – Venkat

2

Вы можете добавить 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]; 
} 
+0

Мне нужно иметь доступ к indexPath ячейки. – ranjha

+0

chk теперь, он даст вам индексный путь ячейки –

+0

Спасибо, яар, я попробую завтра. Shukraan! – ranjha

0

Добавить 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]; 
} 
+0

Мне нужно иметь доступ к indexPath ячейки. – ranjha

+0

Пожалуйста, ознакомьтесь с обновленным ответом –

0

В Alertview делегатом

if (alertView.tag == index) 
{ 
if (buttonIndex == 1) 
{ 
    [yourArray removeObjectAtIndex:alertView.tag-1]; 
    [yourTable reloadData]; 
} 
} 
Смежные вопросы