Home xamarin ios rightbarbuttonitem uialertcontroller not showing in correct spot
Reply: 1

xamarin ios rightbarbuttonitem uialertcontroller not showing in correct spot

user3624640
1#
user3624640 Published in 2017-12-07 18:39:05Z

I have created a rightbarbutton that brings up a memnu. It brings up my menu but at the bottom, I want it to appear under the rightbarbutton. From the xamarin users doc it says I need to set menu.PopoverPresentationController.BarButtonItem to a button which I do, but it always return null for that line. Am I missing something/doimng it wrong?

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

    }
Cole Xia
2#
Cole Xia Reply to 2017-12-08 08:52:37Z

First, you are doing it correctly.

UIPopoverPresentationController can be used in iPhone.

But UIPopoverPresentationController + UIAlertViewController seems not available in iPhone , However we can access it in iPad.

In my test ,menu.PopoverPresentationController always comes to null ,but it works perfectly in iPad.

Test:

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.33008 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO