简体   繁体   English

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

[英]How To Embed MonoTouch.Dialog Elements into ViewController?

I am trying to use this: 我正在尝试使用此:

Adding a Monotouch.Dialog to a standard view 将Monotouch.Dialog添加到标准视图

I can see the view elements when I do this... however clicking on one of the radio elements does not do anything (showing the checkbox for example). 执行此操作时,我可以看到view元素...但是,单击单选元素之一不会执行任何操作(例如,显示复选框)。 Not sure what I am doing wrong. 不知道我在做什么错。

Here is the code that I am using inside ViewDidLoad() 这是我在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);

I found that it was an issue with the dialog controller expanding past the edge of the viewcontroller. 我发现这是对话框控制器超出视图控制器边缘的问题。

The solution was to add a middle UIView as a container to force the DialogController to stay within the correct bounds. 解决方案是添加一个中间的UIView作为容器,以强制DialogController保持在正确的范围内。

The correct code ended up being: 正确的代码最终是:

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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM