指定 .plist 中文件的路径
图像文件 afghanistan.png
位于 iOS 项目资源组中名为 Flags 的组中。我想在 UITableViewCell 中访问此图像。当我调用它时,它返回(null)
。 是否正确?
<string>/Flags/afghanistan.png</string>
文件的路径
<plist version="1.0">
<array>
<dict>
<key>name</key>
<string>Afghanistan</string>
<key>government</key>
<string>Islamic Republic</string>
<key>population</key>
<integer>0</integer>
<key>image</key>
<string>/Flags/afghanistan.png</string>
</dict>
The image file afghanistan.png
is located in a Group called Flags within the Resources Group of an iOS project. I want to access this image in a UITableViewCell. When I call it, it returns (null)
. Is
<string>/Flags/afghanistan.png</string>
the correct path to the file?
<plist version="1.0">
<array>
<dict>
<key>name</key>
<string>Afghanistan</string>
<key>government</key>
<string>Islamic Republic</string>
<key>population</key>
<integer>0</integer>
<key>image</key>
<string>/Flags/afghanistan.png</string>
</dict>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您尝试从项目代码访问此文件,正确的路径将类似于:
这当然假设该文件实际上位于正确的位置。在 .plist 文件中,您可能最好使用完整路径,例如: /Users/username/MyApp/Resources/Flags/afghanistan.png 或任何您的路径。
If your trying to access this file from your project code, the correct path would be something like:
This of course assumes that the file is actually in the right place. In the .plist file, you'd probably be better off using the full path, something like: /Users/username/MyApp/Resources/Flags/afghanistan.png or whatever your path might be.
请记住,Xcode 项目中的文件分组只是一个虚拟“目录”,而不是真实的目录。
考虑到这一点,您可能会发现该图像根本不在 /Flags 目录中,而是在根目录(或另一个完全不同的目录)中。尝试将其更改为
另外,请记住 iPhone 区分大小写,而 Mac 不区分大小写!这可能会导致在模拟器中工作但在手机上不起作用......
Bear in mind that the Grouping of files within an Xcode project is only a virtual "directory", not a real one.
With that in mind, you will probably find that the image is not in a /Flags directory at all, but rather in the root directory (or another completely different one). Try changing it just to
Also, remember that iPhone is case sensitive and Mac isn't! This can lead to things working in the simulator but not on the phone...