public void AddHorizontalConstraintsToSuperviewWidth()
        {
            if (base.Superview == null)
            {
                return;
            }

            UIView child = this;

            Superview.AddConstraints(NSLayoutConstraint.FromVisualFormat("H:|[child]|", 0, null,
                                                                         NSDictionary.FromObjectAndKey(child, new NSString("child"))));
        }
        private void InsertSubview(UIView view)
        {
            Superview.InsertSubviewBelow(view, this);

            var verticalConstraint = NSLayoutConstraint.Create(this, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal,
                                                               view, NSLayoutAttribute.CenterY, 1, 0);
            var leadingConstraint = NSLayoutConstraint.Create(this, NSLayoutAttribute.Leading, NSLayoutRelation.Equal,
                                                              view, NSLayoutAttribute.Leading, 1, 0);
            var trailingConstraint = NSLayoutConstraint.Create(this, NSLayoutAttribute.Trailing, NSLayoutRelation.Equal,
                                                               view, NSLayoutAttribute.Trailing, 1, 0);

            Superview.AddConstraints(new[] { verticalConstraint, leadingConstraint, trailingConstraint });
        }
        private void initialize()
        {
            //Make new tableview and do some settings
            AutoCompleteTableView = new UITableView();
            AutoCompleteTableView.Layer.CornerRadius = 5;                                                                    //rounded corners
            AutoCompleteTableView.ContentInset       = UIEdgeInsets.Zero;
            AutoCompleteTableView.AutoresizingMask   = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight; //for resizing (switching from table to portait for example)
            AutoCompleteTableView.Bounces            = false;
            AutoCompleteTableView.BackgroundColor    = UIColor.Clear;
            AutoCompleteTableView.TranslatesAutoresizingMaskIntoConstraints = false;
            AutoCompleteTableView.Source          = this.AutoCompleteViewSource;
            AutoCompleteTableView.TableFooterView = new UIView();
            AutoCompleteTableView.Hidden          = true;

            //Some textfield settings
            this.TranslatesAutoresizingMaskIntoConstraints = false;
            this.Delegate           = this;
            this.AutocorrectionType = UITextAutocorrectionType.No;
            this.ClearButtonMode    = UITextFieldViewMode.WhileEditing;

            var isTableViewController = _parentTableViewController ?? (_parentViewController as UITableViewController);

            //if parent is tableviewcontroller
            if (isTableViewController != null)
            {
                _parentIsUITableViewController = true;
                if (_parentTableViewController == null)
                {
                    _parentTableViewController = isTableViewController;
                }
                _parentTableViewBounces         = _parentTableViewController.TableView.Bounces;
                _parentTableViewAllowsSelection = _parentTableViewController.TableView.AllowsSelection;

                //Add the view to the contentview of the cell
                Superview.AddSubview(AutoCompleteTableView);

                UITableViewCell cell = Superview.Superview as UIKit.UITableViewCell;

                //Get indexpath to set the constraint to the right cell
                NSIndexPath indexPath = _parentTableViewController.TableView.IndexPathForCell(cell);

                if (indexPath == null)
                {
                    Console.WriteLine("Should be initialized in the ViewDidAppear and not in the ViewDidLoad!");
                    return;
                }
                //add constraints
                Superview.AddConstraints(
                    AutoCompleteTableView.WithSameCenterY(this).Plus((AutocompleteTableViewHeight / 2) + 10 + cell.Frame.Height * indexPath.Row),
                    AutoCompleteTableView.WithSameWidth(this),
                    AutoCompleteTableView.WithSameLeft(this),
                    AutoCompleteTableView.Height().EqualTo(AutocompleteTableViewHeight)
                    );
            }
            else
            {
                Superview.InsertSubviewBelow(AutoCompleteTableView, _parentViewController.View);

                //add constraints
                Superview.AddConstraints(
                    AutoCompleteTableView.AtTopOf(this, this.Frame.Height - 5),
                    AutoCompleteTableView.WithSameWidth(this),
                    AutoCompleteTableView.WithSameLeft(this),
                    AutoCompleteTableView.Height().EqualTo(AutocompleteTableViewHeight)
                    );
            }

            //listen to edit events
            this.EditingChanged += async(sender, eventargs) =>
            {
                if (this.Text.Length > StartAutoCompleteAfterTicks)
                {
                    showAutoCompleteView();
                    await UpdateTableViewData();
                }
            };

            this.EditingDidEnd += (sender, eventargs) =>
            {
                hideAutoCompleteView();
            };
        }