一周前我开始学习Swift 3和Xcode。
此时我有一个带导航栏的小应用程序和右侧的添加按钮,我希望它能够执行某些操作,但我无法弄明白...
我有这个:
func criarPessoa() {
_ = pessoas.append("Ola OLA")
}
let adicionarButao = UIBarButtonItem(barButtonSystemItem: .add, target: self, action: #selector(criarPessoa()(sender:)))
我做错了什么?
答案 0 :(得分:0)
let adicionarButao = UIBarButtonItem(barButtonSystemItem: .add, target: self, action: #selector(criarPessoa()(sender:)))
应该是
let adicionarButao = UIBarButtonItem(barButtonSystemItem: .add, target: self, action: #selector(NameOfTheVCTheFunctionIsIn.criarPessoa()))
您还需要像这样添加BarButton:
self.navigationItem.setLeftBarButtonItems([adicionarButao], animated: false)
或:
self.navigationItem.setRightBarButtonItems([adicionarButao], animated: false)