예제 #1
0
        private void SetUpPicker()
        {
            _picker = new UIPickerView();

            nfloat width = UIScreen.MainScreen.Bounds.Width;

            _Title = new UILabel();
            _Title.TextAlignment = UITextAlignment.Center;

            var toolbar = new UIToolbar(new CGRect(0, 0, (float)width, 44))
            {
                BarStyle    = UIBarStyle.Default,
                Translucent = true
            };
            var cancelButton = new UIBarButtonItem(UIBarButtonSystemItem.Cancel,
                                                   (o, e) =>
            {
                DummyField.ResignFirstResponder();
                Select(_model.PreSelectedItem);
            }
                                                   );

            var labelButton = new UIBarButtonItem(_Title);
            var spacer      = new UIBarButtonItem(UIBarButtonSystemItem.FlexibleSpace);
            var doneButton  = new UIBarButtonItem(UIBarButtonSystemItem.Done,
                                                  (o, a) =>
            {
                _model.OnUpdatePickerFormModel();
                DummyField.ResignFirstResponder();
                _command?.Execute(_model.SelectedItem);
            }
                                                  );

            toolbar.SetItems(new[]
            {
                cancelButton,
                spacer,
                labelButton,
                spacer,
                doneButton
            },
                             false
                             );

            DummyField.InputView          = _picker;
            DummyField.InputAccessoryView = toolbar;

            _model        = new TextPickerSource();
            _picker.Model = _model;

            _model.UpdatePickerFromModel += Model_UpdatePickerFromModel;
        }
예제 #2
0
        /// <summary>
        /// Dispose the specified disposing.
        /// </summary>
        /// <returns>The dispose.</returns>
        /// <param name="disposing">If set to <c>true</c> disposing.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                _model.UpdatePickerFromModel -= Model_UpdatePickerFromModel;
                DummyField.RemoveFromSuperview();
                DummyField?.Dispose();
                DummyField = null;
                _Title?.Dispose();
                _Title = null;
                _model?.Dispose();
                _model = null;
                _picker?.Dispose();
                _picker  = null;
                _command = null;
            }

            base.Dispose(disposing);
        }