WKImage总是返回nil [英] WKImage always return nil

查看:119
本文介绍了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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆