滑动以删除单元格xamarin ios中每次都会降低高度

时间:2016-12-14 03:52:29

标签: ios uitableview xamarin xamarin.ios swipe

我是iOS新手。我正在使用滑动创建TableView以删除单元格。但是当我每次细胞高度降低时都会滑动。我正在使用iOS 10.以下代码我使用过。

代码:

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

1 个答案:

答案 0 :(得分:0)

找到了解决方案。

在TableCell中,我使用下面的代码来分隔两个tableCell并在它们之间留出空间。如果我删除代码,那么它工作正常。

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