public override void ViewDidLoad() { base.ViewDidLoad(); // Initialize the UI to reflect the values of the `shortcutItem`. var selectedShortcutItem = ShortcutItem; if (selectedShortcutItem == null) { throw new InvalidProgramException("The `selectedShortcutItem` was not set."); } Title = selectedShortcutItem.LocalizedTitle; TitleTextField.Text = selectedShortcutItem.LocalizedTitle; SubtitleTextField.Text = selectedShortcutItem.LocalizedSubtitle; // Extract the raw value representing the icon from the userInfo dictionary, if provided. var userInfo = selectedShortcutItem.UserInfo; if (userInfo == null) { return; } var rawNumber = userInfo [AppDelegate.ApplicationShortcutUserInfoIconKey] as NSNumber; if (rawNumber == null) { return; } int row = rawNumber.Int32Value; // Select the matching row in the picker for the icon type. UIApplicationShortcutIconType iconType = IconTypeForSelectedRow(row); // The `iconType` returned may not align to the `iconRawValue` so use the `iconType`'s `rawValue`. PickerView.Select((int)iconType, 0, false); textFieldObserverToken = UITextField.Notifications.ObserveTextFieldTextDidChange((s, e) => { // You cannot dismiss the view controller without a valid shortcut title. DoneButton.Enabled = !string.IsNullOrEmpty(TitleTextField.Text); }); }
public override void PrepareForSegue(UIStoryboardSegue segue, NSObject sender) { var selectedShortcutItem = ShortcutItem; if (selectedShortcutItem == null) { throw new InvalidProgramException("The `selectedShortcutItem` was not set."); } if (segue.Identifier == "ShortcutDetailUpdated") { // In the updated case, create a shortcut item to represent the final state of the view controller. UIApplicationShortcutIconType iconType = IconTypeForSelectedRow((int)PickerView.SelectedRowInComponent(0)); var icon = UIApplicationShortcutIcon.FromType(iconType); var userInfo = new NSDictionary <NSString, NSObject> (AppDelegate.ApplicationShortcutUserInfoIconKey, new NSNumber(PickerView.SelectedRowInComponent(0))); ShortcutItem = new UIApplicationShortcutItem(selectedShortcutItem.Type, TitleTextField.Text ?? string.Empty, SubtitleTextField.Text, icon, userInfo); } }
static UIApplicationShortcutIcon CreateIcon(UIApplicationShortcutIconType type) { return(UIApplicationShortcutIcon.FromType(type)); }
static NSDictionary <NSString, NSObject> CreateUserInfo(UIApplicationShortcutIconType type) { int rawValue = Convert.ToInt32(type); return(new NSDictionary <NSString, NSObject>(ApplicationShortcutUserInfoIconKey, new NSNumber(rawValue))); }
static UIApplicationShortcutIcon CreateIcon (UIApplicationShortcutIconType type) { return UIApplicationShortcutIcon.FromType (type); }
static NSDictionary<NSString, NSObject> CreateUserInfo(UIApplicationShortcutIconType type) { int rawValue = Convert.ToInt32 (type); return new NSDictionary<NSString, NSObject>(ApplicationShortcutUserInfoIconKey, new NSNumber (rawValue)); }