Having trouble getting a custom InputView for UITextField to display

JoshuaCarterJoshuaCarter USUniversity ✭✭

Good morning!
I am having trouble getting a UIView that is loaded from a nib to display as an InputView for a set of UITextFields in my view controller.
It's a simple calculator pad, and does display fine if I manually add the view to the parent view controller.

Here's the definition for the pad


public partial class CalcPad : UIView
    public CalcPad()
        var views = NSBundle.MainBundle.LoadNib("CalcPad", this, null);
        var calcPad = Runtime.GetNSObject(views.ValueAt(0)) as UIView;
    // the Frame is coming across correctly from the xib as { 0, 0, 320, 355 }


And the code from the ViewController that contains the UITextFields I'm trying to use this for. It's a UITableViewController, and the UITextFields are in custom cells.


partial class InventoryViewController : UITableViewController
    public InventoryViewController(IntPtr handle)
        : base(handle)

    public override void ViewDidLoad()

        var cPad = new CalcPad();

        // I've tried this way
        this.txtCarts.InputView = cPad;
        this.txtShelves.InputView = cPad;
        this.txtCases.InputView = cPad;
        this.txtSingles.InputView = cPad;

        // as well as this way, with the same result 
        this.txtCarts.EditingDidBegin += (sender, e) =>
            { this.txtCarts.InputView = cPad; };

        this.txtShelves.EditingDidBegin += (sender, e) =>
            { this.txtShelves.InputView = cPad; };

        this.txtCases.EditingDidBegin += (sender, e) =>
            { this.txtCases.InputView = cPad; };

        this.txtSingles.EditingDidBegin += (sender, e) =>
            { this.txtSingles.InputView = cPad; };
    //.... rest of the set up for other pieces of the view

I'm not sure what I'm missing.. This does stop the default keyboard from displaying, but does not display the UIView. Can anyone see what I'm missing or help point me in the right direction to figure it out?

Thanks in advance


  • JoshuaCarterJoshuaCarter USUniversity ✭✭

    I solved this by switching my UIView to a UIViewController and setting the input view on the UITextFields to the view of the calculator pad's view controller.

Sign In or Register to comment.