简体   繁体   English

无法将多个UIBarButtonItem添加到RightBarButtonItems

[英]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.

相关问题 TableView-无法删除多个单元格 - TableView - Cannot delete more than one cell 无法在多部iPhone上进行测试 - Cannot test on more than one iPhone 在TouchMoved中不能接收到超过一次的触摸 - Cannot receive more than one touch in TouchMoved 在tableView中添加多个SearchBar - Add more than one SearchBar in tableView 无法添加Output,因为不支持多个output同类型 - Cannot add Output because more than one output of the same type is unsupported 声明'subscribe'不能覆盖多个超类声明(ReSwift) - Declaration 'subscribe' cannot override more than one superclass declaration (ReSwift) AVPlayerItem不能与多个AVPlayer实例相关联 - An AVPlayerItem cannot be associated with more than one instance of AVPlayer' nsinvalidargumentexception'reason'avplayeritem无法与多个avplayer实例关联' - nsinvalidargumentexception' reason 'an avplayeritem cannot be associated with more than one instance of avplayer' AVPlayerItem不能与iOS 8.4中的多个AVPlayer实例相关联 - An AVPlayerItem cannot be associated with more than one instance of AVPlayer in iOS 8.4 解析查询-无法处理多个whereKey:doesNotMatchKey:inQuery - Parse Query - cannot process more than one whereKey:doesNotMatchKey:inQuery
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM