예제 #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);
            }
        }
예제 #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;

                        foreach (var e in (Parent as Section).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;
        }
예제 #3
0
        protected override UITableViewCell GetCellImpl(UITableView tv)
        {
            var cell = tv.DequeueReusableCell(CellKey);

            if (cell == null)
            {
                cell = new UITableViewCell(UITableViewCellStyle.Default, CellKey);
                cell.SelectionStyle = UITableViewCellSelectionStyle.None;
            }
            else
            {
                RemoveTag(cell, 1);
            }

            if (_entry == null)
            {
                SizeF size    = ComputeEntryPosition(tv, cell);
                float yOffset = (cell.ContentView.Bounds.Height - size.Height) / 2 - 1;
                float width   = cell.ContentView.Bounds.Width - size.Width;

                _entry = CreateTextField(new RectangleF(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());
                    }

                    RootElement  root  = GetImmediateRootElement();
                    EntryElement focus = null;

                    if (root == null)
                    {
                        return(true);
                    }

                    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)
                    {
                        if (focus != this)
                        {
                            focus.BecomeFirstResponder(true);
                        }
                        else
                        {
                            focus.ResignFirstResponder(true);
                        }
                    }

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

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

                        foreach (var e in (Parent as Section).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;

            cell.TextLabel.Text = Caption;
            cell.ContentView.AddSubview(_entry);
            return(cell);
        }