gpt4 book ai didi

swift - CollectionViewCell 发送上一张图像

转载 作者:行者123 更新时间:2023-11-30 11:04:16 24 4
gpt4 key购买 nike

我正在发送从 collectionView 中选择的图像。问题是应用程序总是发送先前选择的图像。 indexPath 有什么问题?

这是 didSelectItemAt 函数:

override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let options = PHImageRequestOptions()
options.deliveryMode = .highQualityFormat
options.isNetworkAccessAllowed = true
options.isSynchronous = true

PHImageManager.default().requestImage(for: fetchResult.object(at: indexPath.item), targetSize: PHImageManagerMaximumSize, contentMode: .aspectFit, options: options, resultHandler: { image, error in
guard let image = image else { return }
self.image = image

})

performSegue(withIdentifier: "segue099", sender: self)

}

最佳答案

来自Docs

By default, this method executes asynchronously. If you call it from a background thread you may change the isSynchronous property of the options parameter to true to block the calling thread until either the requested image is ready or an error occurs, at which time Photos calls your result handler.

所以

performSegue(withIdentifier: "segue099", sender: self)

在获取图像之前运行,这会导致它传递旧图像,因此要么 true isSynchronous 或将 segue 放入回调内

关于swift - CollectionViewCell 发送上一张图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52920143/

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