我创建了一个右键按钮,可以显示一个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);
}