public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            Bounces                = true;
            ShakeToClearEnabled    = true;
            KeyboardPanningEnabled = true;
            ShouldScrollToBottomAfterKeyboardShows = false;
            Inverted = true;

            LeftButton.SetImage(UIImage.FromBundle("upload.png"), UIControlState.Normal);
            LeftButton.TintColor = UIColor.Gray;

            RightButton.SetTitle("Send", UIControlState.Normal);

            TextInputbar.AutoHideRightButton = true;
            TextInputbar.MaxCharCount        = 256;
            TextInputbar.CounterStyle        = CounterStyle.Split;
            TextInputbar.CounterPosition     = CounterPosition.Top;

            TextInputbar.EditorTitle.TextColor       = UIColor.DarkGray;
            TextInputbar.EditorLeftButton.TintColor  = UIColor.FromRGB(0, 122, 255);
            TextInputbar.EditorRightButton.TintColor = UIColor.FromRGB(0, 122, 255);

            TypingIndicatorView.CanResignByTouch = true;

            TableView.SeparatorStyle = UITableViewCellSeparatorStyle.None;
            TableView.RegisterClassForCellReuse(typeof(MessageTableViewCell), MessengerCellIdentifier);

            AutoCompletionView.RegisterClassForCellReuse(typeof(MessageTableViewCell), AutoCompletionCellIdentifier);

            RegisterPrefixesForAutoCompletion(new [] { "@", "#", ":", "+:" });
        }
        public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath)
        {
            if (this.TableView == tableView)
            {
                var cell = (MessageTableViewCell)TableView.DequeueReusableCell(MessengerCellIdentifier);

                if (cell.TextLabel.Text == null)
                {
                    cell.AddGestureRecognizer(new UILongPressGestureRecognizer(gesture => {
                        if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0))
                        {
                            var alertController = UIAlertController.Create(null, null, UIAlertControllerStyle.ActionSheet);
                            alertController.ModalPresentationStyle = UIModalPresentationStyle.Popover;
                            if (alertController.PopoverPresentationController != null)
                            {
                                alertController.PopoverPresentationController.SourceView = gesture.View.Superview;
                                alertController.PopoverPresentationController.SourceRect = gesture.View.Frame;
                            }
                            alertController.AddAction(UIAlertAction.Create("Edit Message", UIAlertActionStyle.Default, (action) => {
                                EditCellMessage(gesture);
                            }));
                            alertController.AddAction(UIAlertAction.Create("Cancel", UIAlertActionStyle.Cancel, null));
                            NavigationController.PresentViewController(alertController, true, null);
                        }
                        else
                        {
                            EditCellMessage(gesture);
                        }
                    }));
                }

                var message = messages [indexPath.Row];

                cell.TitleLabel.Text = message.Username;
                cell.BodyLabel.Text  = message.Text;
                cell.ThumbnailView.BackgroundColor = message.ProfileColor;

                cell.IndexPath      = indexPath;
                cell.UsedForMessage = true;

                // Cells must inherit the table view's transform
                // This is very important, since the main table view may be inverted
                cell.Transform = TableView.Transform;

                return(cell);
            }
            else
            {
                var cell = (MessageTableViewCell)AutoCompletionView.DequeueReusableCell(AutoCompletionCellIdentifier);
                cell.IndexPath = indexPath;

                var item = searchResult [indexPath.Row];
                if (FoundPrefix == "#")
                {
                    item = "# " + item;
                }
                else if (FoundPrefix == ":" || FoundPrefix == "+:")
                {
                    item = ":" + item;
                }

                cell.TitleLabel.Text = item;
                cell.TitleLabel.Font = UIFont.SystemFontOfSize(14.0f);
                cell.SelectionStyle  = UITableViewCellSelectionStyle.Default;

                return(cell);
            }
        }