Ejemplo n.º 1
0
        protected virtual void MoveFocusToNextElement()
        {
            RootElement  root  = GetImmediateRootElement();
            EntryElement focus = null;

            if (root == null)
            {
                return;
            }

            foreach (var s in root.Sections)
            {
                foreach (var e in s.Elements)
                {
                    if (e == this)
                    {
                        focus = this;
                    }
                    else if (focus != null && e is EntryElement)
                    {
                        focus = e as EntryElement;
                        break;
                    }
                }

                if (focus != null && focus != this)
                {
                    break;
                }
            }

            if (focus == null)
            {
                return;
            }

            if (focus != this)
            {
                focus.BecomeFirstResponder(true);
            }
            else
            {
                focus.ResignFirstResponder(true);
            }
        }
Ejemplo n.º 2
0
        protected virtual void EnsureEntryElement(UITableView tv, UITableViewCell cell)
        {
            if (_entry == null)
            {
                CGSize size    = ComputeEntryPosition(tv, cell);
                nfloat yOffset = (cell.ContentView.Bounds.Height - size.Height) / 2 - 1;
                nfloat width   = cell.ContentView.Bounds.Width - size.Width;

                _entry = CreateTextField(new CGRect(size.Width, yOffset, width, size.Height));

                _entry.ValueChanged   += delegate { FetchAndUpdateValue(); };
                _entry.EditingChanged += delegate { FetchAndUpdateValue(); };
                _entry.Ended          += delegate { FetchAndUpdateValue(); };
                _entry.ShouldReturn   += delegate
                {
                    if (ShouldReturn != null)
                    {
                        return(ShouldReturn());
                    }

                    MoveFocusToNextElement();

                    return(true);
                };
                _entry.Started += delegate
                {
                    EntryElement self = null;

                    if (!returnKeyType.HasValue)
                    {
                        var returnType = UIReturnKeyType.Default;

                        var elements = (Parent as Section)?.Elements;
                        if (elements != null)
                        {
                            foreach (var e in elements)
                            {
                                if (e == this)
                                {
                                    self = this;
                                }
                                else if (self != null && e is EntryElement)
                                {
                                    returnType = UIReturnKeyType.Next;
                                }
                            }
                        }
                        _entry.ReturnKeyType = returnType;
                    }
                    else
                    {
                        _entry.ReturnKeyType = returnKeyType.Value;
                    }

                    tv.ScrollToRow(IndexPath, UITableViewScrollPosition.Middle, true);
                };
            }

            if (_becomeResponder)
            {
                _entry.BecomeFirstResponder();
                _becomeResponder = false;
            }
            _entry.KeyboardType = KeyboardType;

            _entry.AutocapitalizationType = AutocapitalizationType;
            _entry.AutocorrectionType     = AutocorrectionType;
        }