Swift UIBarButtonim操作不工作UITableView单元格
我在UITableView单元格中以编程方式创建UIBarButtonim,如下所示:Swift UIBarButtonim操作不工作UITableView单元格,swift,uitableview,uibarbuttonitem,Swift,Uitableview,Uibarbuttonitem,我在UITableView单元格中以编程方式创建UIBarButtonim,如下所示: func setupChildrenPicker(){ let chooseButton = UIBarButtonItem(title: Wordings.BTN_CHOOSE, style: UIBarButtonItemStyle.done, target: nil, action: #selector(self.pickerChildrenDonePressed)) } func picke
func setupChildrenPicker(){
let chooseButton = UIBarButtonItem(title: Wordings.BTN_CHOOSE, style: UIBarButtonItemStyle.done, target: nil, action: #selector(self.pickerChildrenDonePressed))
}
func pickerChildrenDonePressed(){
print ("pickerChildrenDonePressed")
}
override func awakeFromNib() {
super.awakeFromNib()
setupChildrenPicker()
}
但是当我点击这个按钮时,它并没有调用pickerchildrendepressed()函数(没有创建日志pickerchildrendepressed)
将其命名为PickerChildrenePressed的正确代码是什么?使用以下代码:
里面
uibarbuttonite(标题:Wordings.BTN\u CHOOSE,样式:uibarbuttonimstyle.done,目标:nil,操作:#选择器(self.pickerchildrendepressed)
将目标更改为self
而不是nil使用以下方法:
里面
uibarbuttonite(标题:Wordings.BTN\u CHOOSE,样式:uibarbuttonimstyle.done,目标:nil,操作:#选择器(self.pickerchildrendepressed)
将target更改为
self
而不是nil您应该共享更多可编译的代码来重现问题。是否有任何具体原因使用uiBarButtonim
而不是uiButtonim
?我认为除了导航栏、工具栏和选项卡栏之外,您不应该在其他位置使用uiBarButtonim
。对于其他位置,请使用UIButton
。您使用UIBarButtonItem
而不是UIButton
是否有特定原因,因为当我单击tableview单元格中的“自定义”按钮时,它将调用pickerView。而且pickerView是自定义的。UIBarButtonItem会在左上方和右上方创建,完成并取消。您可以吗UIButton替换该UIBarButtonim?在UIBarButtonim中设置目标(标题:words.BTN_CHOOSE,样式:uiBarButtonimStyle.done,目标:nil,操作:#选择器(self.pickerChildren pressed)
将其改为self而不是nil@ShubhamBakshi,您的答案是正确的。谢谢。您应该共享更多可编译的代码来重现此问题。是否有任何具体原因使用UIBarButtonItem
而不是UIButton
?我认为除了导航栏、工具栏、选项卡B之外,您不应该在其他地方使用UIBarButtonItem
ar.对于其他位置,请使用UIButton
。您使用UIBarButtonItem
而不是UIButton
是否有特定原因,因为当我单击tableview单元格中的自定义按钮时,它将调用pickerView。并且pickerView是自定义的。UIBarButtonItem将在左上方和右上方创建,完成并取消。UIButton可以替换该UIBarButtonim吗?将uiBarButtonim中的目标(标题:words.BTN\u CHOOSE,样式:uiBarButtonimStyle.done,目标:nil,操作:#选择器(self.pickerChildrendepressed)
设置为self而不是selfnil@ShubhamBakshi,你的答案是正确的。谢谢。