2017-07-21 19 views
0

的時候,這裏是我的代碼表視圖細胞開始搖晃試圖滑動刪除當前單元

func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) { 

     print("editingStyle") 
     if editingStyle == .delete { 

      //Doing my task 

     } 
} 

我每次向左滑動,其他細胞開始搖晃,並創建一個非常糟糕的用戶體驗。 我已經嘗試了一些黑客喜歡

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) ->UITableViewCell { 
    if let cell = tableView.dequeueReusableCell(withIdentifier: kCellReuseCardIdentifier) as? MyCustomTableViewCell { 

      let frame = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width - 16, height: 125) 
      cell.frame = frame 
      cell.contentView.frame = frame 
//   Cells get squished when editing mode is enabled. To prevent that from happening , we create a dummy cell 
      let dummyCell = tableView.dequeueReusableCell(withIdentifier: kDummyCellIdentifier) as! DummySpaceTableViewCell 
      dummyCell.addSubview(cell.contentView) 
      dummyCell.clipsToBounds = true 

      return dummyCell 
} 

有趣的是,這個hack作品的iOS測試版11。在iOS 10中,這會導致單元晃動問題。請注意,我的tableView有n部分,每個部分有行。請幫忙。

回答

0
I have used MGSwipeTableCell to prevent from above issue. 
You can find the code & examples from below link. 
https://github.com/MortimerGoro/MGSwipeTableCell 

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
    { 
    experienceCell * experienceCell = [tableView dequeueReusableCellWithIdentifier:@"experienceCell"]; 
    MGSwipeButton *DeleteButton=[MGSwipeButton buttonWithTitle:@"" icon:[UIImage imageNamed:@"delete_white"] backgroundColor:THEME_COLOR padding:15]; 

       DeleteButton.titleLabel.font=ROBOTO_REGULAR_FONT16; 

       experienceCell.rightSwipeSettings.transition=MGSwipeTransitionStatic; 
       experienceCell.rightExpansion.buttonIndex=0; 
       experienceCell.rightExpansion.fillOnTrigger=true; 
       [email protected][DeleteButton]; 
       experienceCell.delegate = self; 
       experience = true; 
    return experienceCell; 
    } 
    -(BOOL) swipeTableCell:(MGSwipeTableCell*) cell tappedButtonAtIndex:(NSInteger) index direction:(MGSwipeDirection)direction fromExpansion:(BOOL) fromExpansion 
{ 
if(direction == MGSwipeDirectionRightToLeft && index == 0) 
{ 
} 

return YES; 
}