0

GlassButtonがクリックされたときに画面を変更する方法を探しています。Monotouch.Dialog の学習を始めたばかりです。これを試して処理するために、次のことを行いました。

public override void ViewDidLoad ()
    {

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

list は ですUIViewControllerが、クリックthis.NavigationController.PushViewController(list, true);すると null 参照例外で指されます。 listはインスタンス化されており、null ではありませんが、this.NavigationControllernull です。どうすればこれを修正できますか?

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
                    }
                }
            }
        };
    }
4

1 に答える 1

0

同じ問題があり、サブクラスを派生させることで解決しました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);
于 2014-06-02T07:18:26.350 に答える