gpt4 book ai didi

swift - 用户第一次在collectionview Swift 5中添加图像单元时显示选择的图像而不是默认图像

转载 作者:行者123 更新时间:2023-11-30 10:37:48 25 4
gpt4 key购买 nike

我是 iOS 开发和 swift 5 编码新手。我有一个 Collection View ,用户可以向其中添加图像。有两个问题。首先,我希望当用户第一次查看 Collection View 时不显示任何单元格。第二个问题是,当用户添加第一张图像时,它显示默认图像/单元格,而不是从图像选择器中选择的图像。

我已搜索此答案,但没有找到任何可以帮助解决我的问题的内容。谢谢

我向 numberOfItemsInSection 函数添加了负 1。当我运行它时,它在 Collection View 中没有显示任何单元格。但是,当我添加图像/单元格时,会显示默认图像/单元格,而不是用户从照片库中选择的图像。

// collectionviewcell
class CollectionViewCell: UICollectionViewCell {

@IBOutlet weak var img: UIImageView!

var delegate: CollectionProtocol?
var index: IndexPath?

@IBOutlet weak var deleteBtn: UIButton!
@IBAction func deleteBtn(_ sender: UIButton) {
delegate?.deleteData(indx: (index?.row)!)
print("photo deleted")
}
}


// view controller
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return imgArr.count - 1
}

最佳答案

我需要将 imageArray 初始化为空状态。所以我将其更新为:让 imageArray = UIImage

还更新了 func numberOfItemsInSection 以返回 numberOfRowsInSection

关于swift - 用户第一次在collectionview Swift 5中添加图像单元时显示选择的图像而不是默认图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57545808/

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