Exemple #1
0
        public override UITableViewCell GetCell(UITableView tv)
        {
            if (cell == null)
            {
                cell = new UITableViewCell(UITableViewCellStyle.Default, cellkey);
                cell.SelectionStyle = UITableViewCellSelectionStyle.None;
            }
            cell.TextLabel.Text = Caption;

            var offset = (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Phone) ? 20 : 90;

            cell.Frame = new CGRect(cell.Frame.X, cell.Frame.Y, tv.Frame.Width - offset, cell.Frame.Height);
            CGSize size    = ComputeEntryPosition(tv, cell);
            var    yOffset = (cell.ContentView.Bounds.Height - size.Height) / 2 - 1;
            var    width   = cell.ContentView.Bounds.Width - size.Width;

            if (textalignment == UITextAlignment.Right)
            {
                // Add padding if right aligned
                width -= 10;
            }
            var entryFrame = new CGRect(size.Width, yOffset + 2f, width, size.Height);

            if (entry == null)
            {
                entry = CreateTextField(entryFrame);
                entry.ValueChanged += delegate {
                    FetchValue();
                };
                entry.EditingChanged += delegate {
                    FetchValue();
                };
                entry.Ended += delegate {
                    FetchValue();
                    if (EntryEnded != null)
                    {
                        EntryEnded(this, null);
                    }
                };
                entry.ShouldReturn += delegate {
                    if (ShouldReturn != null)
                    {
                        return(ShouldReturn());
                    }

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

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

                    foreach (var s in root)
                    {
                        foreach (var e in s)
                        {
                            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 != this)
                    {
                        focus.BecomeFirstResponder(true);
                    }
                    else
                    {
                        focus.ResignFirstResponder(true);
                    }

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

                    if (EntryStarted != null)
                    {
                        EntryStarted(this, null);
                    }

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

                        foreach (var e in Section)
                        {
                            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);
                };
                cell.ContentView.AddSubview(entry);
            }
            else
            {
                entry.Frame = entryFrame;
            }

            if (becomeResponder)
            {
                entry.BecomeFirstResponder();
                becomeResponder = false;
            }
            entry.KeyboardType = KeyboardType;

            entry.AutocapitalizationType = AutocapitalizationType;
            entry.AutocorrectionType     = AutocorrectionType;
            cell.TextLabel.Text          = Caption;
            cell.TextLabel.Font          = TitleFont;
            cell.TextLabel.TextColor     = TitleColor;

            return(cell);
        }