如何在自定义大小的MonoTouch对话框中修复EntryElement的滚动?

时间:2012-11-20 23:57:33

标签: iphone uitableview uiviewcontroller xamarin.ios monotouch.dialog

我做了一些与this问题非常相似的事情。我创建了一个MonoTouch DialogViewController,其中包含一堆EntryElements,用于捕获用户注册的信息。然后我将这个DialogViewController添加到另一个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);

当用户点击EntryElement时会出现问题。键盘出现,前几个EntryElements一切都很好,因为键盘没有隐藏任何东西。当您进入EntryElements时,DialogViewController不再滚动键盘上方的元素。基本上,DialogViewController的滚动会中断。

这是通过将DialogViewController的View添加到另一个视图中引起的。它通常在将DialogViewController推送到UINavigationController时非常有效:

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

这是一个错误还是我可以覆盖以修复滚动的内容?

修改

截屏1: 带有一些EntryElements的DialogViewController。我已向下滚动到底部 - Last Name上面有更多EntryElements。

enter image description here

截屏2: 点击Email EntryElement时会发生什么。你可以非常清楚地看到DVC没有滚动表视图,而它通常会这样做。

enter image description here

1 个答案:

答案 0 :(得分:0)

您可以尝试继承DialogViewController类,而不是将DialogViewController视图添加到另一个View中。如果你这样做,问题就会消失。我不知道这是否是一种很好的方式,但我在生产中成功使用它。以下是我通常的做法,注意RootElement最初在基础构造函数中是如何为空,但我们在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
    }
}

此外,如果要在表单上方或下方添加内容,可以在页面中添加页眉和页脚 - Section类的HeaderView和FooterView属性。