这曾经在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版本进行尝试均未成功。有没有我没有研究过的额外设置?
答案 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]