[英]Cannot add more than one UIBarButtonItem to RightBarButtonItems
This used to work in previous versions of Xamarin, but now I cannot add more than one right UIBarButtonItem to my UIViewController NavigationItem. 这曾经在Xamarin的早期版本中起作用,但是现在我不能在UIViewController NavigationItem中添加多个正确的UIBarButtonItem。 I've checked all the relevant questions here and elsewhere and this still does not work for me. 我已经在这里和其他地方检查了所有相关问题,但这仍然对我不起作用。
Here's my code: 这是我的代码:
var addButton = new UIBarButtonItem(UIBarButtonSystemItem.Add, ((object sender, EventArgs e) =>
{
}));
var pauseButton = new UIBarButtonItem(UIBarButtonSystemItem.Pause, ((object sender, EventArgs e) =>
{
}));
this.NavigationItem.RightBarButtonItems = new UIBarButtonItem[] { addButton, pauseButton };
Any suggestions would be welcome as I've tried targeting different iOS versions with no success. 任何建议都将受到欢迎,因为我尝试针对不同的iOS版本进行了尝试,但均未成功。 Is there an extra setting I haven't looked into? 有没有我没有考虑过的额外设置?
Simply add this code: 只需添加以下代码:
self.navigationItem.leftBarButtonItem = nil
let firstRightButton = UIButton(type: .system)
button.setImage(UIImage (named: "ChatTab"), for: .normal)
button.frame = CGRect(x: 0.0, y: 0.0, width: 35.0, height: 35.0)
//button.addTarget(target, action: nil, for: .touchUpInside)
let barButtonItem = UIBarButtonItem(customView: firstRightButton)
let secondRightButton = UIButton(type: .custom)
button2.setImage(UIImage (named: "ActivityTab"), for: .normal)
button2.frame = CGRect(x: 0.0, y: 0.0, width: 35.0, height: 35.0)
//button.addTarget(target, action: nil, for: .touchUpInside)
let barButtonItem2 = UIBarButtonItem(customView: secondRightButton)
self.navigationItem.rightBarButtonItems = [barButtonItem, barButtonItem2]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.