我有一个定制的UICollectionViewCell,里面有一个按钮。当我点击按钮时,会在该子类中触发一个事件。然后,我想在UICollectionView本身上触发一个事件,我可以在视图控制器中处理这个事件。
伪码:
class MyCell : UICollectionViewCell {
@IBAction func myButton_touchUpInside(_ sender: UIButton) {
// Do stuff, then propagate an event to the UICollectionView
Event.fire
假设我正在开发一个电子商务应用程序,我必须用他们的price-tag(it will be UILabel)、product description(in UILabel)和buy(UIButton) button显示产品列表。产品图像将来自web服务器,它可以是数千个。
因此,我选择了UICollectionView而不是UITableview,以获得更吸引人的外观。对于购买按钮,我在UICollectionView的单元格中添加了UIButton。但我不能从UILabel上找到插座,上面写着illegal configuration。那么,选择UICollectionView来显示来自后端