2013-02-27 143 views

回答

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 2013-02-27 04:52:47

+0

看到所有人都告訴我添加GestureRecognizer。 – ranjha 2013-02-27 04:55:12

+0

不便之處...... – Venkat 2013-02-27 04:57:26

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 2013-02-27 04:55:27

+0

chk現在,它會給你單元格的路徑 – 2013-02-27 04:58:40

+0

謝謝,亞爾,我會明天再試。 Shukraan! – ranjha 2013-02-27 04:59:45

0

添加UISwipeGestureRecognizerCell

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 2013-02-27 04:55:54

+0

請看最新的答案 – 2013-02-27 05:06:19

0

在Alertview委託

if (alertView.tag == index) 
{ 
if (buttonIndex == 1) 
{ 
    [yourArray removeObjectAtIndex:alertView.tag-1]; 
    [yourTable reloadData]; 
} 
}