2013-02-13 117 views
0

我試過了,但刷卡不觸發tableView:willBeginEditingRowAtIndexPath:根本!和刪除按鈕從不出現,有沒有解決方法?我可以在自定義的uitableviewcell中使用滑動刪除功能嗎?

編輯:這是我實現

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    return YES; 
} 
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    return YES; 
} 

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    return UITableViewCellEditingStyleDelete; 
} 

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    [tableView beginUpdates]; 
    if (editingStyle == UITableViewCellEditingStyleDelete) 
    { 
     if(_itemsArray == nil) 
      NSLog(@"\n\nNIL ARRAY\n\n"); 
     NSLog(@"\nindexPath.row = %d\nItemsArray Count:%d",indexPath.row,_itemsArray.count); 
     int row = [[[_itemsArray objectAtIndex:indexPath.row]valueForKey:@"itemRow"] integerValue]; 
     [_itemsArray removeObjectAtIndex:indexPath.row]; 
     [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; 
     [[self delegate]didDeletedBillItemRow:row]; 
    } 

    [tableView endUpdates]; 
} 
+0

在定製的tableview細胞禁用用戶交互 – NANNAV 2013-02-13 07:31:17

+0

使tableview.setEditing = YES; – Vinodh 2013-02-13 08:44:32

回答

7

tableView:willBeginEditingRowAtIndexPath:不是處理這個正確的地方。從官方文檔,你需要在你實現這個方法的UITableViewController:

注:要啓用的表視圖輕掃到刪除功能(其中 用戶跨行水平揮筆顯示刪除按鈕),你的 必須執行tableView:commitEditingStyle:forRowAtIndexPath: 方法。

就這樣:

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    if (editingStyle == UITableViewCellEditingStyleDelete) 
    { 
     //add code here for when you hit delete 
    }  
} 
+1

也確保在tableview中返回YES:canEditRowAtIndexPath: – pre 2013-02-13 08:30:22

+1

tableview:canEditRowAtIndexPath返回YES和tableView:commitEditingStyle:已實現 – Mhdali 2013-02-13 08:52:16

相關問題