3

I have done something very similar to this question. I have created a MonoTouch DialogViewController which has a bunch of EntryElements in it used to capture information for a user registering. I then add this DialogViewController into another UIViewController:

            registerDialog = new RegisterDialog (); // the dvc
            registerDialog.View.Frame = new RectangleF (0, 60, 320, View.Frame.Height - 60);
            registerDialog.TableView.BackgroundView = null; // make the background transparent
            Add (registerDialog.View);

The problem comes when the user clicks on an EntryElement. The keyboard shows up and for the first few EntryElements everything is fine as the keyboard does not hide anything. As you progress through the EntryElements, the DialogViewController no longer scrolls the elements above the keyboard. Basically the scrolling of the DialogViewController breaks.

This is caused by adding the DialogViewController's View into another view. It works perfectly when pushing the DialogViewController onto a UINavigationController normally:

NavigationController.PushViewController (new LoginScreen (), true);

Is this a bug or is there something I can override to fix the scrolling?

EDIT

Screenshot 1: The DialogViewController with some EntryElements. I have scrolled down to the bottom - there are more EntryElements above Last Name.

enter image description here

Screenshot 2: What happens when I tap the Email EntryElement. You can very clearly see the DVC has not scrolled the table view up whereas it normally does this.

enter image description here

Community
  • 1
  • 1
Dylan
  • 1,919
  • 3
  • 27
  • 51

1 Answers1

0

Instead of adding the DialogViewController View into another View, you can try subclassing the DialogViewController class. The issue will be gone if you do it like that. I don't know if this is a good way of doing it but I use it successfully in production. Here is how I usually do it, notice how the RootElement is initially empty in the base constructor, but we add the content in ViewDidLoad.

public class MyController : DialogViewController
{
    public MyController() : base(new RootElement(""), true)
    {
    }

    public override void ViewDidLoad() 
    {
        var section1 = new Section("Credentials") 
        {
            new EntryElement("Username", null, null),
            new EntryElement("Password", null, null)
        };

        Root.Add(section1);
       // additional initialization here
    }
}

Also, if you want to add something above or below your form, you can add headers and footers to sections - the HeaderView and FooterView properties of the Section class.

Jivko Petiov
  • 586
  • 7
  • 15