这是我的代码:
override func viewDidLoad() {
super.viewDidLoad()
let addButton = UIBarButtonItem(barButtonSystemItem: .action
, target: self, action: #selector(tapButton))
let addButton1 = UIBarButtonItem(barButtonSystemItem: .add
, target: self, action: #selector(tapButton1))
navigationItem.rightBarButtonItem = [addButton,addButton1]
}
@IBAction func tapButton(_ sender: Any){
print("your tap")
let shareText = "share to others"
let activityViewController = UIActivityViewController(activityItems: [shareText], applicationActivities: nil)
present(activityViewController, animated: true, completion: nil)
}
@IBAction func tapButton1(_ sender: Any){
print("your tap1")
}
我遇到错误
无法分配类型“ [UIBarButtonItem]”的值来键入 这行中的'UIBarButtonItem?'“” navigationItem.rightBarButtonItem = [addButton,addButton1]
出什么问题了?
答案 0 :(得分:1)
将其更改为
navigationItem.rightBarButtonItems = [addButton,addButton1]