public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            ActionSetCreator = new ActionSetCreator(ActionSet, Home);
            displayedAccessories.Clear();
            displayedAccessories.AddRange(Home.SortedControlAccessories());

            TableView.RegisterClassForCellReuse(typeof(UITableViewCell), accessoryCell);
            TableView.RegisterClassForCellReuse(typeof(UITableViewCell), unreachableAccessoryCell);
            TableView.RegisterClassForCellReuse(typeof(ActionCell), actionCell);

            TableView.RowHeight = UITableView.AutomaticDimension;

            TableView.EstimatedRowHeight = 44;

            var actionSet = ActionSet;

            if (actionSet != null)
            {
                NameField.Text = actionSet.Name;
                NameFieldDidChange(NameField);
            }

            NameField.Enabled &= Home.IsAdmin();
        }
        // - returns:  An `ActionCell` instance with the target value for the characteristic at the specified index path.
        UITableViewCell GetActionCell(UITableView tableView, NSIndexPath indexPath)
        {
            var cell           = (ActionCell)tableView.DequeueReusableCell(actionCell, indexPath);
            var characteristic = ActionSetCreator.AllCharacteristics() [indexPath.Row];

            NSObject target = ActionSetCreator.TargetValueForCharacteristic(characteristic);

            if (target != null)
            {
                cell.SetCharacteristic(characteristic, (NSNumber)target);
            }

            return(cell);
        }
 // Removes the action associated with the index path.
 public override void CommitEditingStyle(UITableView tableView, UITableViewCellEditingStyle editingStyle, NSIndexPath indexPath)
 {
     if (editingStyle == UITableViewCellEditingStyle.Delete)
     {
         var characteristic = ActionSetCreator.AllCharacteristics() [indexPath.Row];
         ActionSetCreator.RemoveTargetValueForCharacteristic(characteristic, () => {
             if (ActionSetCreator.ContainsActions)
             {
                 tableView.DeleteRows(new [] { indexPath }, UITableViewRowAnimation.Automatic);
             }
             else
             {
                 tableView.ReloadRows(new [] { indexPath }, UITableViewRowAnimation.Automatic);
             }
         });
     }
 }
        // returns:  In the Actions section: the number of actions this set will contain upon saving.
        // In the Accessories section: The number of accessories in the home.
        public override nint RowsInSection(UITableView tableView, nint section)
        {
            switch ((ActionSetTableViewSection)(int)section)
            {
            case ActionSetTableViewSection.Name:
                return(base.RowsInSection(tableView, section));

            case ActionSetTableViewSection.Actions:
                return(Math.Max(ActionSetCreator.AllCharacteristics().Length, 1));

            case ActionSetTableViewSection.Accessories:
                return(displayedAccessories.Count);

            default:
                throw new InvalidOperationException("Unexpected `ActionSetTableViewSection` value.");
            }
        }
        void SaveAndDismiss()
        {
            SaveButton.Enabled = false;

            ActionSetCreator.SaveActionSetWithName(TrimmedName, error => {
                SaveButton.Enabled = true;

                if (error != null)
                {
                    DisplayError(error);
                }
                else
                {
                    Dismiss();
                }
            });
        }
		public override void ViewDidLoad ()
		{
			base.ViewDidLoad ();

			ActionSetCreator = new ActionSetCreator (ActionSet, Home);
			displayedAccessories.Clear ();
			displayedAccessories.AddRange (Home.SortedControlAccessories ());

			TableView.RegisterClassForCellReuse (typeof(UITableViewCell), accessoryCell);
			TableView.RegisterClassForCellReuse (typeof(UITableViewCell), unreachableAccessoryCell);
			TableView.RegisterClassForCellReuse (typeof(ActionCell), actionCell);

			TableView.RowHeight = UITableView.AutomaticDimension;

			TableView.EstimatedRowHeight = 44;

			var actionSet = ActionSet;
			if (actionSet != null) {
				NameField.Text = actionSet.Name;
				NameFieldDidChange (NameField);
			}

			NameField.Enabled &= Home.IsAdmin ();
		}