2016-12-14 40 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

这就是为什么如此重要的共享完整的解决方案,而不仅仅是代码段:-) –