没有为UIBarButtonItem调用iOS选择器



我有一些相当简单的代码,正在试图弄清楚为什么uibarbuttonitem没有触发选择器:

TableView的viewDidLoad方法:

override func viewDidLoad() {
super.viewDidLoad()
// Uncomment the following line to preserve selection between presentations
self.clearsSelectionOnViewWillAppear = false
// this line adds a button to top right
let addNewChecklistItemButton = UIBarButtonItem(barButtonSystemItem: .add,
target: nil,
action: #selector(self.addNewChecklistItemToDataModel))
self.navigationItem.rightBarButtonItem = addNewChecklistItemButton
}

方法调用:

@objc func addNewChecklistItemToDataModel() {
print("adding new item...")
<...>
}

按钮正在添加中(在我输入此代码之前不可见(,当我按下它时,按钮点击会产生动画,但我的控制台不会显示打印的文本。

在阅读UIBarButtonItem选择器不工作后,我想知道我的UITableViewController嵌入在UITabViewControllerUINavigationViewController中这一事实是否会影响按钮的作用域?如果没有,有人看到我缺少的东西吗

目标不应为零

let addNewChecklistItemButton = UIBarButtonItem(barButtonSystemItem: .add,
target: self,
action: #selector(self.addNewChecklistItemToDataModel))

最新更新