gpt4 book ai didi

ios - 调用 [UIImage imageWithData :xxx] multiple times

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:45:54 25 4
gpt4 key购买 nike

我的模型来自 Core Data。我的 bean 将图像作为 NSData 存储在模型中。

要显示我的图像,我需要做:

[UIImage imageWithData:bean.imageData] 

如果我到处都这样做可以吗?我的意思是,从 View #1 开始,我通过创建 [UIImage imageWithData:] 来显示图像,然后我继续 View #2,在那里我需要显示相同的图像,但我只在两个 View 之间传递 bean,所以我重新创建了 UIImage使用 [UIImage imageWithData]。

我想知道如果我这样做是否需要太多的 CPU 或内存...我需要自己管理缓存吗?我认为这可能是 CoreData 非常常见的用例,那么是否有一种通用的模式来处理这个问题?

最佳答案

imageWithData 不会缓存您的图像(根据文档,唯一要缓存的 UIImage 方法是 imageNamed)

Here is an algorithm不过,用于缓存图像。

关于ios - 调用 [UIImage imageWithData :xxx] multiple times,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18604853/

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