NavigationItem.SetRightBarButtonItems 引发异常
如果我在导航栏上只设置一个右键,它就可以正常工作。 但是,当我尝试设置多个按钮时,它们出现了,但单击它们会引发异常。
EventHandler pickPhotoClickHandler = (s,e) => {}; //Do nothing
var pickPhotoBtn = new UIBarButtonItem(UIBarButtonSystemItem.Camera, pickPhotoClickHandler);
EventHandler sendBtnClickHandler = (s, e) => {}; //Do nothing
var sendBtn = new UIBarButtonItem (UIBarButtonSystemItem.Done, sendBtnClickHandler);
NavigationItem.SetRightBarButtonItem (pickPhotoBtn, animated:true); // This works
var btns = new UIBarButtonItem[]{sendBtn,pickPhotoBtn}; // This doesn't
NavigationItem.SetRightBarButtonItems(btns,true); // go very far
我做错了什么?
If I set only one right button on the NavBar it works perfectly.
But when I'm trying to set more than one button, they showed up, but clicking on them throws exceptions.
EventHandler pickPhotoClickHandler = (s,e) => {}; //Do nothing
var pickPhotoBtn = new UIBarButtonItem(UIBarButtonSystemItem.Camera, pickPhotoClickHandler);
EventHandler sendBtnClickHandler = (s, e) => {}; //Do nothing
var sendBtn = new UIBarButtonItem (UIBarButtonSystemItem.Done, sendBtnClickHandler);
NavigationItem.SetRightBarButtonItem (pickPhotoBtn, animated:true); // This works
var btns = new UIBarButtonItem[]{sendBtn,pickPhotoBtn}; // This doesn't
NavigationItem.SetRightBarButtonItems(btns,true); // go very far
What am I doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我设法通过创建从
UIbarButtonItem
派生的新类并使用 IntPtr 定义构造函数来解决这个问题,现在它可以工作了
I managed to fix that by creating new class derived from
UIbarButtonItem
and defining a constructor with IntPtrNow it works
看看这个:http://osmorphis.blogspot.com /2009/05/multiple-buttons-on-navigation-bar.html
如果你想为 iOS 添加多个右键< /2009/05/multiple-buttons-on-navigation-bar.html 它可以工作。 5.0
经过尝试和测试! :D
Check this out: http://osmorphis.blogspot.com/2009/05/multiple-buttons-on-navigation-bar.html
It works if you want to add multiple right buttons for iOS < 5.0
Tried and tested! :D