访问资产图像将始终返回nil,这是我的代码和资产目录屏幕截图.
Access assets image will always return nil, below is my code and assets catalog screen shot.
let image = WKImage(imageName: "sample") print(image.image)这将始终显示为零.
更新:更新了屏幕截图
推荐答案我发现从您的屏幕截图中,您正在swiftWatch WatchOS 目标,我想您正在将该图像用于WKDemo目标,因此您得到的是零.
I found that from your screenshot you are setting the Image Set in Assests.xcassets in the swiftWatch WatchOS target and i think you are use that image for the WKDemo target so you get that nil.
在您的WKDemo's Assests.xcassets中而不是WatchOS的Assests.xcassets中设置该图像集,然后进行检查.
Set that Image Set in your WKDemo's Assests.xcassets instead of WatchOS's Assests.xcassets then check.
问题在于您正在其他目标中设置 ImageSet ,并且尝试在其他目标中加载.
That issue is your are setting ImageSet in different Target and your are try to load in Different Target.
更新
检查示例项目后,您正在执行错误的代码来获取图像.代替let image = WKImage(imageName: "sample"),您必须使用WKPickerItem()对象,例如以下代码:
After checking your sample project you are doing wrong code for getting image. Instead of let image = WKImage(imageName: "sample") you must be use WKPickerItem() object like following code:
for i in 1...10 { let item = WKPickerItem() item.title = "Picker itme =\(i)" item.contentImage = WKImage(imageName: "sample") if let image = item.contentImage { print(image) } pickerItems.append(item) }输出是
更多推荐
WKImage总是返回nil
发布评论