简体   繁体   中英

Xamarin Forms MasterDetail Page Not Working on iOS

I have an app setup and I have been testing it with Android pretty successfully but now I am trying to add in iOS and it doesn't seem to work at all.

I have a MasterDetailPage that I mostly copied from the mobileCRM project which works fine for me on Adroid and my buildhost but not in my ported over version.

public class RootPage : MasterDetailPage
{
    OptionItem _previousItem;

    public RootPage()
    {
        var optionsPage = new MenuPage { Icon = "Icon.png", Title = "menu" };

        optionsPage.Menu.ItemSelected += (sender, e) => NavigateTo(e.SelectedItem as OptionItem);

        Master = optionsPage;

        NavigateTo(optionsPage.Menu.ItemsSource.Cast<OptionItem>().First());
    }

    void NavigateTo(OptionItem option)
    {
        if (_previousItem != null)
            _previousItem.Selected = false;

        option.Selected = true;
        _previousItem = option;

        var displayPage = PageForOption(option);
        Detail = new NavigationPage(displayPage)
        {
            BarBackgroundColor = Helpers.Color.Orange.ToFormsColor()
        };

        Detail.SetValue(TitleProperty, option.Title);
        Detail.SetValue(IconProperty, option.Icon);

        IsPresented = false;
    }

    static Page PageForOption(OptionItem option)
    {
        switch (option.Title)
        {
            case "Home":
                return new HomePage();
            case "Circles":
                return new CirclesPage();
            case "Settings":
                return new SettingsPage ();
            default:
                throw new NotImplementedException("Unknown menu option: " + option.Title);
        }
    }
}

This looks like a bug in Xamarin.Forms , and I've reported it.

I was able to reproduce your issue, but also able to workaround it by replacing the ListView in OptionPage by a StackLayout of Buttons :

public MenuPage (MasterDetailPage mdpage)
{
    Content = new StackLayout {
        Children = {
            new Button { Text = "Home", Command = new Command (() => {mdpage.Detail = new HomePage ();mdpage.IsPresented = false;}) },
            new Button { Text = "Circles", Command = new Command (() => {mdpage.Detail = new CirclesPage ();mdpage.IsPresented = false;}) },
            new Button { Text = "Settings", Command = new Command (() => {mdpage.Detail = new SettingsPage ();mdpage.IsPresented = false;}) },
        }
    };
}

In one of my projects, I'm using a TableView in the Master , but just like the ListView here, it triggers the issue.

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