// Handle supported edits to the data source (inserts and deletes).
        public override void CommitEditingStyle(UITableView tableView, UITableViewCellEditingStyle editingStyle, NSIndexPath indexPath)
        {
            // Respond to the user's edit request: Insert a new statistic definition, or delete an existing one.
            if (editingStyle == UITableViewCellEditingStyle.Insert)
            {
                // Create an overlay UI that lets the user choose a field and statistic type to add.
                _chooseStatOverlay = new ChooseStatisticOverlay(_statPicker);

                // Handle the OnStatisticDefined event to get the info entered by the user.
                _chooseStatOverlay.OnStatisticDefined += (s, statDef) =>
                {
                    // Verify the selected statistic doesn't exist in the collection (check for an alias with the same value).
                    StatisticDefinition existingItem = _statisticDefinitions.Find(itm => itm.OutputAlias == statDef.OutputAlias);
                    if (existingItem != null)
                    {
                        return;
                    }

                    // Make updates to the table (add the chosen statistic).
                    tableView.BeginUpdates();

                    // Insert a new row at the top of table display.
                    tableView.InsertRows(new[] { NSIndexPath.FromRowSection(0, 0) }, UITableViewRowAnimation.Fade);

                    // Insert the chosen statistic in the underlying collection.
                    _statisticDefinitions.Insert(0, statDef);

                    // Apply table edits.
                    tableView.EndUpdates();
                };

                // Handle when the user chooses to close the dialog.
                _chooseStatOverlay.OnCanceled += (s, e) =>
                {
                    // Remove the item input UI.
                    _chooseStatOverlay.Hide();
                    _chooseStatOverlay = null;
                };

                // Add the picker UI view (will display semi-transparent over the table view).
                tableView.AddSubview(_chooseStatOverlay);

                _chooseStatOverlay.TranslatesAutoresizingMaskIntoConstraints = false;
                _chooseStatOverlay.LeadingAnchor.ConstraintEqualTo(tableView.SafeAreaLayoutGuide.LeadingAnchor).Active =
                    true;
                _chooseStatOverlay.TrailingAnchor.ConstraintEqualTo(tableView.SafeAreaLayoutGuide.TrailingAnchor)
                .Active = true;
                _chooseStatOverlay.BottomAnchor.ConstraintEqualTo(tableView.SafeAreaLayoutGuide.BottomAnchor).Active = true;
            }
            else if (editingStyle == UITableViewCellEditingStyle.Delete)
            {
                // Remove the selected row from the table and the underlying collection of statistic definitions.
                _statisticDefinitions.RemoveAt(indexPath.Row);
                tableView.DeleteRows(new[] { indexPath }, UITableViewRowAnimation.Fade);
            }
        }
Ejemplo n.º 2
0
        // Handle supported edits to the data source (inserts and deletes)
        public override void CommitEditingStyle(UITableView tableView, UITableViewCellEditingStyle editingStyle, NSIndexPath indexPath)
        {
            // Respond to the user's edit request: Insert a new statistic definition, or delete an existing one
            if (editingStyle == UITableViewCellEditingStyle.Insert)
            {
                // Get the bounds of the table
                CGRect ovBounds = tableView.Bounds;
                ovBounds.Height = ovBounds.Height + 60;

                // Create an overlay UI that lets the user choose a field and statistic type to add
                _chooseStatOverlay = new ChooseStatisticOverlay(ovBounds, 0.70f, UIColor.White, _statPicker);

                // Handle the OnStatisticDefined event to get the info entered by the user
                _chooseStatOverlay.OnStatisticDefined += (s, statDef) =>
                {
                    // Verify the selected statistic doesn't exist in the collection (check for an alias with the same value)
                    StatisticDefinition existingItem = _statisticDefinitions.Find(itm => itm.OutputAlias == statDef.OutputAlias);
                    if (existingItem != null)
                    {
                        return;
                    }

                    // Make updates to the table (add the chosen statistic)
                    tableView.BeginUpdates();

                    // Insert a new row at the top of table display
                    tableView.InsertRows(new[] { NSIndexPath.FromRowSection(0, 0) }, UITableViewRowAnimation.Fade);

                    // Insert the chosen statistic in the underlying collection
                    _statisticDefinitions.Insert(0, statDef);

                    // Apply table edits
                    tableView.EndUpdates();
                };

                // Handle when the user chooses to close the dialog
                _chooseStatOverlay.OnCanceled += (s, e) =>
                {
                    // Remove the item input UI
                    _chooseStatOverlay.Hide();
                    _chooseStatOverlay = null;
                };

                // Add the picker UI view (will display semi-transparent over the table view)
                tableView.Add(_chooseStatOverlay);
            }
            else if (editingStyle == UITableViewCellEditingStyle.Delete)
            {
                // Remove the selected row from the table and the underlying collection of statistic definitions
                _statisticDefinitions.RemoveAt(indexPath.Row);
                tableView.DeleteRows(new[] { indexPath }, UITableViewRowAnimation.Fade);
            }
        }