Grid: Using a TextField in a popover to edit cell


#1

Hi,

I’m evaluating your grid and arising thereby some issues. I hope it’s just because I’m unexperienced :wink:
I use the Xamarin-Bindings (Xamarin.IOS / MonoTouch)

I have a simple ShinobiDataGrid with two Columns. Each use the CellType of “SDataGridTextCell”. In the “SDataGridDelegate” I’m overriding the method “OnBeginEditingCell” with the following code:

var cell = grid.VisibleCellAtCoordinate(coordinate) as SDataGridTextCell;
            var cellTextField = cell.TextField as SGridTextField;
            cellTextField.InputView = new UITextView();

            var viewController = new UIViewController();
            var navBar = new UIToolbar(new RectangleF(0, 0, viewController.View.Bounds.Width, 50)) {BarStyle = UIBarStyle.Black, Translucent = true, Items = new[] { new UIBarButtonItem(UIBarButtonSystemItem.Done, (s, e) => {_popoverController.Dismiss(true);})}};
            navBar.SizeToFit();
            var textField = new UITextField(new RectangleF(0, 50, viewController.View.Bounds.Width, viewController.View.Bounds.Height)) { Placeholder = "Mein Text...", BackgroundColor = UIColor.White };


            viewController.View.Add(navBar);
            viewController.View.Add(textField);
            _popoverController = new UIPopoverController(viewController);
            _popoverController.SetPopoverContentSize(new SizeF(250, 200), false);
            _popoverController.PresentFromRect(cell.Bounds, cell.TextField.Superview, UIPopoverArrowDirection.Any, false);

In this case I’m not able to set the focus directly to the TextField in the Popover to start entering text without tapping into the popover again. And I’d like to prevent the user to enter any text directly to the textfield. Something like readonly. But setting the cell.TextView.Enabled = false will be ignored in any case.

A tried out a second way to achieve a custom input. Therefore I set the InputView property of the cell.TextField. But the only thing happens is that neither the keyboard nor the custom input view appears.

I’m looking forward to get very soon an answer. :wink:

Best regards,
Danny


Swift: Shinobi Grid show PopOver when selected
#2

Hi dannyyy,

It seems like you have two text fields so I’ll discuss each separately:

1. Cell’s text field:  SDataGridTextCell’s handle text input by managing their corresponding TextField directly - this allows them to do things like only allow editing on double taps rather than single taps. This means that trying to set properties such as Enabled on an SDataGridTextCell’s TextField instance will be overriden depending on whether you have your column set to editable or not. If you want a readonly text cell it’d probably be much easier to provide your own SDataGridCell subclass that manages a UILabel - then you don’t have to worry about trying to manage if it’s editable or not and focus on managing its text content.

2. Pop over’s text field:  You can make text fields start editing without user interaction by making them become first responder (BecomeFirstResponder). This means that when you are telling your _popoverController to present you should also be able to tell textField to become first responder. I suspect that PresentFromRect may result in your pop over appearing on the next run loop (rather than immediately) so telling your text field to become first responder in the OnBeginEditingCell may not work as your call may happen prior to the pop over appearing. If that’s the case then there are some Cocoa methods you can use to be notified of your text view’s appearance, at which point you can tell it to become first responder.

Hope the above suggestions help!  :grin: