WKImage总是返回nil

编程入门 行业动态 更新时间:2024-10-25 23:37:10
本文介绍了WKImage总是返回nil的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

访问资产图像将始终返回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

本文发布于:2023-10-19 19:18:39,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1508509.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:WKImage   nil

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!