xamarin ios rightbarbuttonitem uialertcontroller没有显示正确的位置

时间:2017-12-07 18:39:06

标签: ios xamarin uialertcontroller

我创建了一个右键按钮,可以显示一个memnu。它会显示我的菜单,但在底部,我希望它显示在右侧按钮下方。从xamarin用户文档中我说我需要将menu.PopoverPresentationController.BarButtonItem设置为我所做的按钮,但它总是为该行返回null。我错过了什么/做错了吗?

        var customBtn = new UIBarButtonItem();
        customBtn.Image = UIImage.FromFile("images/hamburger.png");
        _button = customBtn;
        customBtn.Clicked += (object sender, EventArgs e) =>
        {
            NavActionMenu(sender);
        };

        NavigationItem.RightBarButtonItem = customBtn;





    private void NavActionMenu(object sender)
    {
        UIAlertController menu = UIAlertController.Create("Menu", null, UIAlertControllerStyle.ActionSheet);

        UIAlertAction actionMail = (UIAlertAction.Create("Mail", UIAlertActionStyle.Default, (Action) =>
        {
            try
            {
                appD.type = "Mail";
                appD.user = _user;
                UIStoryboard sb = UIStoryboard.FromName("Main", null);
                var view = sb.InstantiateViewController("MailViewController") as MailViewController;
                appD.navCtrl.PushViewController(view, true);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.InnerException.Message);
            }
        }));

        UIAlertAction actionUserEdit = (UIAlertAction.Create("User", UIAlertActionStyle.Default, (Action) =>
        {
            try
            {
                appD.type = "Edit";
                appD.user = _user;
                UIStoryboard sb = UIStoryboard.FromName("Main", null);
                var view = sb.InstantiateViewController("SignupViewController") as SignupViewController;
                appD.navCtrl.PushViewController(view, true);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.InnerException.Message);
            }
        }));

        UIAlertAction actionLogout = (UIAlertAction.Create("Logout", UIAlertActionStyle.Default, (Action) =>
        {
            try
            {
                appD.user = null;
                UIStoryboard sb = UIStoryboard.FromName("Main", null);
                var view = sb.InstantiateViewController("ViewController") as ViewController;
                appD.navCtrl.PushViewController(view, true);
            }
           catch (Exception e)
            {
                Console.WriteLine(e.InnerException.Message);
            }
        }));

        menu.AddAction(actionMail);
        menu.AddAction(actionUserEdit);
        menu.AddAction(actionLogout);
        //menu.PopoverPresentationController.BarButtonItem = _button;

        this.PresentViewController(menu, true, null);

    }

1 个答案:

答案 0 :(得分:0)

首先,你正确地做到了。

<xsl:variabe name='another_file' select='document("foo.xml")/' /> 可以在iPhone中使用。

UIPopoverPresentationController + UIPopoverPresentationController似乎在iPhone中无法使用,但我们可以在iPad上访问它。

在我的测试中,UIAlertViewController总是变为空,但它在iPad中完美运行。

测试:

enter image description here