无法将多个UIBarButtonItem添加到RightBarButtonItems

时间:2018-10-20 07:32:24

标签: ios iphone xamarin.ios

这曾经在Xamarin的早期版本中起作用,但是现在我不能在UIViewController NavigationItem中添加多个正确的UIBarButtonItem。我已经在这里和其他地方检查了所有相关问题,但这仍然对我不起作用。

这是我的代码:

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

任何建议都将受到欢迎,因为我尝试针对不同的iOS版本进行尝试均未成功。有没有我没有研究过的额外设置?

1 个答案:

答案 0 :(得分:2)

只需添加以下代码:

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]