Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift 使用UIImage从包含名称的字符串中显示本地图像_Swift - Fatal编程技术网

Swift 使用UIImage从包含名称的字符串中显示本地图像

Swift 使用UIImage从包含名称的字符串中显示本地图像,swift,Swift,有什么想法吗?我得到一个错误,说要更改我的ImageName的格式,我想这肯定是正确的 按照阿克塞尔的建议,现在更像这样 myCell.sourceIcon.image = [UIImage imageNamed:@item.sourceIcon!]; 其中,顺便说一下,item.sourceicon!=“英国广播公司” 另外,输出错误是Swift isUIImage(名为:“yourImageName”)Thank Axel:)中的EXC_I386_INVOPUIImage构造函数。您的解

有什么想法吗?我得到一个错误,说要更改我的ImageName的格式,我想这肯定是正确的

按照阿克塞尔的建议,现在更像这样

 myCell.sourceIcon.image = [UIImage imageNamed:@item.sourceIcon!];
其中,顺便说一下,item.sourceicon!=“英国广播公司”


另外,输出错误是Swift is
UIImage(名为:“yourImageName”)
Thank Axel:)中的EXC_I386_INVOP

UIImage构造函数。您的解决方案非常有效。我以
myCell.sourceIcon.image=UIImage(名为:“imagename”)
的方式运行它,但现在我尝试了以下方法:
myCell.sourceIcon.image=UIImage(名为:item.sourceIcon!)
但这些图像现在似乎不起作用。请详细说明“item.sourceIcon!”。构造函数应该像Axel建议的那样简单。我觉得你没有正确地指向图像。也用一只手打开包装!(砰)接线员并不总是个好主意。我建议使用一个可选的绑定(如果let{})语句。sourceIcon是一个可选的字符串,包含要以这种格式“image.png”加载的图像的名称
myCell.sourceIcon?.image = UIImage(named:item.sourceIcon!)