【发布时间】:2020-12-22 21:45:08
【问题描述】:
我有一个带有标题标签的自定义集合视图单元子类。我想将单元格的标题标签更改为操作表中所选操作的标题。我尝试在处理程序中执行此操作,但无法通过处理程序访问单元格标签。
这是操作表的代码
func dailyInjuryIllnessActionSheet() {
let alert = UIAlertController(title: "Title", message: "Select an Option", preferredStyle: .actionSheet)
//alert.addAction(UIAlertAction(title: "Available for Full Participation", style: .default, handler: nil))
alert.addAction(UIAlertAction(title: "Available for Full Participation", style: .default, handler: { (action) in
/// Change the cell text - Get the `UILabel`, and replace the text with `action.title`
}))
alert.addAction(UIAlertAction(title: "Available for Limited Participation", style: .default, handler: nil))
alert.addAction(UIAlertAction(title: "Not Available For Participation", style: .default, handler: nil))
alert.addAction(UIAlertAction(title: "Close Injury / Illness", style: .default, handler: nil))
alert.addAction(UIAlertAction(title: "Cancel", style: .destructive, handler: nil))
present(alert, animated: true, completion: nil)
}
这是单元格的代码:
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: DIISDetailCell.reuseIdentifier, for: indexPath) as? DIISDetailCell else { return UICollectionViewCell() }
if let entries = player?.entries {
for entry in entries {
cell.eventName.text = entry.injuryIllnessName
cell.eventDate.text = entry.statusDate.formatted()
cell.eventType.text = entry.status
cell.modifiedBy.text = entry.modifiedBy ?? "Modified By Goes Here"
}
}
return cell
}
我整个星期都被困在这个问题上。
我在哪里调用代码:
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
dailyInjuryIllnessActionSheet()
}
【问题讨论】:
-
你在哪里打电话
dailyInjuryIllnesActionSheet? -
我在 didSelectItemAt @paulw11 中调用它
-
请edit您的问题显示代码。您可以将单元格传递给函数,也可以将完成处理程序传递给函数并更新完成处理程序中的标签
-
我刚刚解决了我的问题。如果你有时间,你能告诉我你的意思吗? UILabel 被定义为单元格子类。