繁体   English   中英

Xamarin Forms MasterDetail页面无法在iOS上使用

[英]Xamarin Forms MasterDetail Page Not Working on iOS

我有一个应用程序设置,并且已经在Android上非常成功地对其进行了测试,但是现在我试图在iOS中添加它,它似乎根本无法正常工作。

我有一个MasterDetailPage,主要是从mobileCRM项目复制的,对我在Adroid和我的buildhost上工作正常,但在移植的版本上不行。

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

这看起来像Xamarin.Forms的错误,我已经报告了它。

我能够重现您的问题,但也可以通过将OptionPageListView替换为ButtonsStackLayout来解决此问题:

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

在我的一个项目中,我在Master使用TableView,但是就像这里的ListView一样,它触发了问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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