UIBarButtonItem action not work UITableView cell

回眸只為那壹抹淺笑 提交于 2020-01-30 12:24:50

问题


I create UIBarbUttonItem inside UITableView cell programmatically like this :

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()
}

but when I click that BarButtonItem, it not called pickerChildrenDonePressed() function (did not create log pickerChildrenDonePressed).

What is the correct code to make it called pickerChildrenDonePressed?


回答1:


Use this :

Inside

UIBarButtonItem(title: Wordings.BTN_CHOOSE, style:UIBarButtonItemStyle.done, target: nil, action: #selector(self.pickerChildrenDonePressed)

change target to self instead of nil



来源:https://stackoverflow.com/questions/53040005/uibarbuttonitem-action-not-work-uitableview-cell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!