2013-12-10 113 views
0

我有一個tableview和一個單元格:D與選擇披露附件。我用故事板創建了所有UI元素。 (沒放視圖中單元格的內容) 我使用SWTableViewCell實現刷卡只是到刪除,但一切似乎都做工精細,除了當我把一個斷點上的方法刷卡刪除

#pragma mark -SWTableViewDelegate- 

-(void)swipeableTableViewCell:(SWTableViewCell *)cell didTriggerRightUtilityButtonWithIndex:(NSInteger)index 
{ 

    NSIndexPath *path=[self.table indexPathForCell:cell]; 
    [anArray removeObjectAtIndex:path.row]; 
    [self.table deleteRowsAtIndexPaths:@[path] withRowAnimation:UITableViewRowAnimationRight]; 
} 

,這將有助於你明白我只是在這裏做

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 

    SWTableViewCell *cell=(SWTableViewCell*)[tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath]; 
    if (!cell) 
    { 

     NSMutableArray *rightUtilityButtons = [NSMutableArray new]; 
     [rightUtilityButtons sw_addUtilityButtonWithColor:[UIColor colorWithRed:1.0f 
                     green:0.231f 
                     blue:0.188 
                     alpha:1.0f] 
    title:@"Delete"]; 

     cell = [[SWTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell" containingTableView:_table leftUtilityButtons:nil rightUtilityButtons:rightUtilityButtons]; 
    } 

    NSMutableDictionary *deDict=[[NSMutableDictionary alloc]initWithDictionary:[anArray objectAtIndex:indexPath.row]]; 

    cell.textLabel.text= [deDict objectForKey:@"Name"]; 

    return cell; 
} 

然而,我沒有得到任何錯誤,因爲當我嘗試刷卡上模擬器,它根本不工作..

回答

0

無需使用SWTableViewCell只需覆蓋followi NG支持有條件的編輯的UITableView委託的內置方法&滑動刪除

有條件編輯- 可選 -

//Override this method only if you are going to be returning NO for some items. 
//By default, all items are editable. 
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    // Return YES if you want the specified item to be editable. 
    return YES; 
} 

的滑動刪除

// Override to support editing the table view. 
// for swipe to delete 
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { 
    if (editingStyle == UITableViewCellEditingStyleDelete) { 
     //add code here for when you hit delete 
    }  
} 
+2

他們不是'UITableView'方法,你不會覆蓋它們。他們是委託方法。 – Sulthan

+0

嗯,我現在正在做commitEdittingStyle和titleForDeleteConfirmationButtonForRowAtIndexPath,看到的作品 – user3079947

+0

那麼沒關係,不需要擔心它只是從右向左滑動,你會看到刪除按鈕,它按照commitEdittingStyle按下時執行操作 –