gpt4 book ai didi

swift - ios8/swift : Buttons inside UICollectionView Cell?

转载 作者:可可西里 更新时间:2023-11-01 01:42:27 26 4
gpt4 key购买 nike

我正在尝试使用 Collection View 将“上传图像”的预览构建到服务器,但不知何故我被删除了——或者更准确地说,如何正确连接单元格内的按钮?

Collection Cell

单击 X(单元格内的一个按钮)时,用户应该从属于其父 ViewController 的上传数组中删除此 UIImage。

您应该在自定义单元格类中还是在普通 ViewController 中处理 IBAction 单击?

正确的做法是什么?您应该根据索引在按钮上使用标签,然后删除图像 @index 还是应该将整个数组移交给单元格并在点击后返回?

最佳答案

假设按钮的 Touch Up Inside 事件连接到下面的函数。

func deleteButtonPressed(button: UIButton) {
let touchPoint = collectionView.convertPoint(CGPoint.zeroPoint, fromView: button)
if let indexPath = collectionView.indexPathForItemAtPoint(touchPoint) {
// now you know indexPath. You can get data or cell from here.
}
}

关于swift - ios8/swift : Buttons inside UICollectionView Cell?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28347878/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com