gpt4 book ai didi

ios - UIImage imageWithContentsOfFile 正确的pathForResource

转载 作者:可可西里 更新时间:2023-11-01 06:24:38 25 4
gpt4 key购买 nike

我有资源:

Test.png
test1.jpg
tesT2.jpg
tEst3.jpg

我需要在 UIImageView 中显示此图像。所以我写道:

imgView.image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[myObject.filename stringByDeletingPathExtension] ofType:[myObject.filename pathExtension]]];

myObject 是我模型中的实体。我从 xml 中获取 filename,但在 xml 中它的格式如下:

filename="test.png"
filename="test1.jpg"
filename="test3.jpg"
filename="test3.jpg"

所以我的图像是 (null) 因为在 pathForResource 我搜索 @"test"ofType "png",但需要 @"Test"ofType"png ".

如何在不重命名的情况下获取正确的资源?

最佳答案

如果您不能重命名源数据(您确实应该这样做),那么您将需要使用文件管理器来获取所有可用文件的列表,然后执行不区分大小写的过滤器来获取匹配项命名并使用它。

关于ios - UIImage imageWithContentsOfFile 正确的pathForResource,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22062575/

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