简体   繁体   中英

xamarin.mac / monomac switch betweeen views

I'm following this tutorial trying to change between different views on my application. Because the tutorial is written in Objective-C and not C# it's kinda hard for me to translate (I'm a newbie in C# and no Objective-C experience). This is my current code that doesn't work (error in line ourViewController = constFirstView; ):

    public const int constFirstViewTag = 0;
    public const int constSecondViewTag = 1;

    public NSViewController ourViewController = new NSViewController();

    partial void changeView (NSObject sender)
    {
        var item = sender as NSToolbarItem;
        int tag = Convert.ToInt32(item.Tag);

        changeViewController(tag);
    }

    public void changeViewController(int tag)
    {
        switch (tag) {
        case constFirstViewTag:
            ourViewController = new GeneralController();
            break;
        case constSecondViewTag:
            ourViewController = new AccountController();
            break;
        }

        ourView.AddSubview (ourViewController.View);
    }

ourView is my customView control. The code from the tutorial you can see here . Thanks in advance!

Ok, I've got the solution. Here's the working switch-statement (I also updated the code above):

switch (tag) {
    case constFirstViewTag:
        ourViewController = new GeneralController();
        break;
    case constSecondViewTag:
        ourViewController = new AccountController();
        break;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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