2016-12-14 27 views
0

我是iOS新手。我用滑動創建TableView來刪除單元格。但是當我每次刷單元格高度降低時都會滑動。我正在使用iOS 10.我已經使用了下面的代碼。滑動刪除單元格xamarin ios中的高度每次都會減少

代碼:

class AppointmentSourceClass : UITableViewSource 
    { 
     List<AppointmentItem> appointments; 

     public AppointmentSourceClass(List<AppointmentItem> appointments) 
     { 
      this.appointments = appointments; 
     } 

     public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath) 
     { 
      ApointListCell cell = tableView.DequeueReusableCell(ApointListCell.Key) as ApointListCell ?? ApointListCell.Create(); 
      var item = appointments[indexPath.Row]; 

      cell.BindData(item); 

      cell.Layer.MasksToBounds = false; 
      cell.Layer.CornerRadius = 5.0f; 
      cell.BackgroundColor = UIColor.White; 
      cell.SelectionStyle = UITableViewCellSelectionStyle.None; 

      return cell; 
     } 

     public override void CommitEditingStyle(UITableView tableView, UITableViewCellEditingStyle editingStyle, NSIndexPath indexPath) 
     { 
      switch (editingStyle) 
      { 
       case UITableViewCellEditingStyle.Delete: 
        appointments.RemoveAt(indexPath.Row); 
        tableView.DeleteRows(new NSIndexPath[] { indexPath},UITableViewRowAnimation.Fade); 
        break; 
       case UITableViewCellEditingStyle.None: 
        break; 
      } 
     } 

     public override bool CanEditRow(UITableView tableView, NSIndexPath indexPath) 
     { 
      return true; 
     } 

     public override string TitleForDeleteConfirmation(UITableView tableView, NSIndexPath indexPath) 
     { 
      return "Trash ("; 
     } 

     public override nint RowsInSection(UITableView tableview, nint section) 
     { 
      return appointments.Count; 
     } 
    } 
} 

輸出:

掃取圖像之前:

enter image description here

後刷卡圖片:

enter image description here

回答

0

找到解決方案。

在TableCell中,我使用下面的代碼來分離兩個tableCell並在它們之間留出空間。如果我刪除代碼,那麼它工作正常。

public override CoreGraphics.CGRect Frame 
     { 
      get 
      { 
       return base.Frame; 
      } 
      set 
      { 
       value.Y += 4; 
       value.Height -= 2 * 4; 
       base.Frame = value; 
      } 
     } 
+0

這就是爲什麼如此重要的共享完整的解決方案,而不僅僅是代碼段:-) –

相關問題