【问题标题】:How To Embed MonoTouch.Dialog Elements into ViewController?如何将 MonoTouch.Dialog 元素嵌入 ViewController?
【发布时间】:2014-10-03 17:59:08
【问题描述】:

我正在尝试使用这个:

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

【问题讨论】:

    标签: ios xamarin.ios monotouch.dialog radioelement


    【解决方案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);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-14
      • 1970-01-01
      • 1970-01-01
      • 2012-07-07
      • 2012-01-19
      相关资源
      最近更新 更多