如何将MonoTouch.Dialog元素嵌入到ViewController中?

时间:2014-10-03 17:59:09

标签: ios xamarin.ios monotouch.dialog radioelement

我正在尝试使用它:

Adding a Monotouch.Dialog to a standard view

当我这样做时,我可以看到视图元素...但是点击其中一个无线电元素不会做任何事情(例如显示复选框)。不确定我做错了什么。

以下是我在ViewDidLoad()

中使用的代码
    var rootElement = new RootElement("Question Text", new RadioGroup("answer", 0))
    {
       new Section()
       {
            new RadioElement("Answer A", "answer"),
            new RadioElement("Answer B", "answer"),
            new RadioElement("Answer C", "answer"),
            new RadioElement("Answer D", "answer")
        }
     };

     _questionDialogViewController = new DialogViewController(rootElement);
     _questionDialogViewController.View.BackgroundColor = UIColor.Clear.FromHexString(AppDelegate.EventModel.MainBackgroundColor);
     _questionDialogViewController.View.Frame = new RectangleF(0, 250, 864, 500);
     View.AddSubview(_questionDialogViewController.View);

1 个答案:

答案 0 :(得分:1)

我发现对话框控制器扩展到视图控制器的边缘是个问题。

解决方案是添加一个中间UIView作为容器,以强制DialogController保持在正确的范围内。

正确的代码最终成为:

var rootElement = new RootElement("Question Text", new RadioGroup("answer", 0))
{
   new Section()
   {
        new RadioElement("Answer A", "answer"),
        new RadioElement("Answer B", "answer"),
        new RadioElement("Answer C", "answer"),
        new RadioElement("Answer D", "answer")
    }
 };

 _questionDialogViewController = new DialogViewController(rootElement);
 _questionDialogViewController.View.BackgroundColor = UIColor.Clear.FromHexString(AppDelegate.EventModel.MainBackgroundColor);
 _questionDialogViewController.View.Frame = new RectangleF(0, 0, 964, 500);

 var answerContainer = new UIView(new RectangleF(30, 150, 964, 500));
 answerContainer.AddSubview(_questionDialogViewController.View);

 View.AddSubview(answerContainer);