【发布时间】:2017-05-22 21:58:28
【问题描述】:
我正在使用带有 UICollectionView 的自定义单元格,我需要以编程方式为每个单元格定义 UIButton。
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cellId", for: indexPath) as! ClinicListCell
cell.title.text = clinicNames[indexPath.row]
cell.subTitle.text = clinicSubs[indexPath.row]
cell.backgroundImageView.image = UIImage(named: clinicImages[indexPath.row])
cell.profileBtn.tag = indexPath.row
cell.profileBtn.addTarget(self, action: Selector(("profileBtnClicked:")), for: .touchUpInside)
return cell
}
并且我在同一个类中定义了以下选择器方法。
class func profileBtnClicked(sender:UIButton) {
print("Selected")
}
我尝试从选择器方法中删除类/静态,但它总是给我unrecognized selector sent to instance 错误,我哪里出错了?
谢谢。
【问题讨论】:
-
您应该发布完整/完整的错误消息(包括信息 which 选择器无法识别)