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

그래서 코드 조각이 아닌 완벽한 솔루션을 공유하는 것이 중요합니다. –