C# 插入CommittedItingStyle Monotouch

C# 插入CommittedItingStyle Monotouch,c#,ios,xamarin.ios,C#,Ios,Xamarin.ios,基本上,我想要的是,如果单击编辑按钮,则会在列表中添加一个创建单元格,该单元格将导航到单独的屏幕控制器进行添加。我目前有删除工作以及插入,它只是插入一个空白单元格到您的表。有人能帮忙吗?谢谢以下是我的代码 private class UserAlertsTableViewSource : UITableViewSource { const string DEFAULT_CELL = "UserAlertsCell"; private UserAler

基本上,我想要的是,如果单击编辑按钮,则会在列表中添加一个创建单元格,该单元格将导航到单独的屏幕控制器进行添加。我目前有删除工作以及插入,它只是插入一个空白单元格到您的表。有人能帮忙吗?谢谢以下是我的代码

private class UserAlertsTableViewSource : UITableViewSource

    {

        const string DEFAULT_CELL = "UserAlertsCell";

        private UserAlertsListController _useralertslistController;

        public UserAlertsTableViewSource( UserAlertsListController useralertslistController)
        {
            this._useralertslistController = useralertslistController;  
        }



        public override int RowsInSection(UITableView tableView, int section)
        {
            return _useralertslistController.Alerts.Count;

        }

        public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath)
        {
            int row = indexPath.Row;

            var cell = tableView.DequeueReusableCell(DEFAULT_CELL) as UserAlertsCell;   


            if (null == cell) {
                cell = new UserAlertsCell();
                var views = NSBundle.MainBundle.LoadNib("UserAlertsCell", cell, null);
                cell = Runtime.GetNSObject(views.ValueAt(0)) as UserAlertsCell;


            }




            cell.Name = _useralertslistController.Alerts[indexPath.Row].LakeName;
                cell.AlertLevel = _useralertslistController.Alerts[indexPath.Row].AlertLevel;
            cell.AlertVariance = _useralertslistController.Alerts[indexPath.Row].AlertVariance;





            return cell;
        }


        public override void RowSelected(UITableView tableView, NSIndexPath indexPath)
        {
            SelectItem (tableView, indexPath);
        }

        public override void AccessoryButtonTapped(UITableView tableView, NSIndexPath indexPath)
        {
            SelectItem(tableView, indexPath);
        }

        public override float GetHeightForRow(UITableView tableView, NSIndexPath indexPath)
        {
            return 60f;

        }

        public void SelectItem(UITableView tableView, NSIndexPath indexPath)
        {
        //  MapController mapController = new MapController();
        //  _lakelevelsController.NavigationController.PushViewController(mapController, true);
        }


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



    public override UITableViewCellEditingStyle EditingStyleForRow (UITableView tableView, NSIndexPath indexPath)
        {

            var count = this._useralertslistController.Alerts.Count;
            if (indexPath.Row == count-1 )
            {
                return UITableViewCellEditingStyle.Insert;
            }else
            {
                return UITableViewCellEditingStyle.Delete;
            }





        }




        public override void CommitEditingStyle (UITableView tableView, UITableViewCellEditingStyle editingStyle, NSIndexPath indexPath)
        {

        switch (editingStyle)
            {
            case UITableViewCellEditingStyle.Delete:

            this._useralertslistController.Alerts.RemoveAt (indexPath.Row);
            tableView.DeleteRows (new NSIndexPath[] { indexPath } , UITableViewRowAnimation.Fade);
                break;


            case UITableViewCellEditingStyle.Insert:
            this._useralertslistController.Alerts.Insert ( indexPath.Row, new AlertSettings ());
                tableView.InsertRows (new NSIndexPath[] { indexPath }, UITableViewRowAnimation.Fade); 

                break;

            case UITableViewCellEditingStyle.None:
                Console.WriteLine ("CommitEditingStyle: None called");
                break;

        }
        }

        public override void MoveRow (UITableView tableView, NSIndexPath sourceIndexPath, NSIndexPath destinationIndexPath)
        {

            var item = this._useralertslistController.Alerts[sourceIndexPath.Row];
            int deleteAt = sourceIndexPath.Row;
            if (destinationIndexPath.Row < sourceIndexPath.Row)
            {
                deleteAt = sourceIndexPath.Row + 1;
            }
            this._useralertslistController.Alerts.Insert (destinationIndexPath.Row, item);
            this._useralertslistController.Alerts.RemoveAt (deleteAt);



        }



    }

在GetCell和RowSelected方法中,只需在创建单元格时添加大小写即可

if (indexPath.Row == _useralertscontroller.Alerts.Count)
{
  // this is the +1 cell, so do something special
}

您还需要修改RowsInSection以添加一个额外的行。

到底是什么问题?它在做什么或不做什么?为什么不总是显示Create单元格而不是将其绑定到edit按钮中?谢谢Jason刚才在想这个。。如何将该单元格转换为navigationdialog单元格,同时保持所有其他单元格不变?