【问题标题】:MonoTouch Dialog--Null Navigation ControllerMonoTouch Dialog--Null 导航控制器
【发布时间】:2013-06-26 13:30:04
【问题描述】:

我正在寻找一种在单击GlassButton 时更改屏幕的方法。我刚刚开始学习 Monotouch.Dialog。我已经做了以下尝试来处理这个问题。

public override void ViewDidLoad ()
    {

        button.TouchUpInside += (sender, e) => {
            this.NavigationController.PushViewController(list, true);
        };
    } 

list 是一个UIViewController,但在单击时,this.NavigationController.PushViewController(list, true); 被指向一个空引用异常。 list 已被实例化并且不为空,但是,this.NavigationController 为空。我该如何解决这个问题?

GlassButton button = new GlassButton (new RectangleF(0, 0, 200, 50));
List list = new List ();
public static EntryElement lastName = new EntryElement (null, "Enter Last Name", null);
public static EntryElement firstName = new EntryElement (null, "Enter First Name", null);
public static EntryElement middleInitial = new EntryElement (null, "Enter Middle Initial", null);

    public practice () : base (UITableViewStyle.Grouped, null)
    {
        Root = new RootElement ("Level 1") {
            new Section() {
                new RootElement("Level 2") {
                    new Section("Individual Information") {
                        lastName, firstName, middleInitial
                    },

                    new Section("Submit") {
                        button
                    }
                }
            }
        };
    }

【问题讨论】:

    标签: c# xamarin.ios xamarin monotouch.dialog


    【解决方案1】:

    我遇到了同样的问题,并通过从 DialogViewController 派生子类来解决

    public class CustomDialogViewController : DialogViewController
    {
            public CustomDialogViewController(RootElement root)
                : base(null, true)
            {
                base.Root = root;
            }
    }
    

    在我的主视图控制器中,我在 ViewDidLoad() 中使用了以下内容:

    var root = new RootElement("Customer form");
    // code to generate section and add into root
    CustomDialogViewController customDialogViewController = new CustomDialogViewController(root);
    var navigationController = new UINavigationController(customDialogViewController);
    
    this.AddChildViewController(this.navigationController);
    this.View.AddSubview(this.navigationController.View);
    

    【讨论】:

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