首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何让图片在集合式视图(Json)中显示?

如何让图片在集合式视图(Json)中显示?
EN

Stack Overflow用户
提问于 2015-04-11 23:11:17
回答 1查看 194关注 0票数 0

我试着写的应用程序,数据可以显示的形式Json和显示在集合视图,但问题是只有文本可以显示,而不是图片。有没有人能帮上忙,或者给我一些建议?

代码语言:javascript
复制
var collection = [LabelClass]()
let kiaLoandURL = "http://xxxx.com/?json=get_recent_posts/json=1&count=10&custom_fields=PostThumb&include=title,content,thumbnail"

override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {

let cell = collectionView.dequeueReusableCellWithReuseIdentifier(reuseIdentifier, forIndexPath: indexPath) as CustomCollectionViewCell

cell.nameLabel.text = collection[indexPath.row].title
cell.nameImage.image = UIImage(named: collection[indexPath.row].image) // not working

 return cell  

}

代码语言:javascript
复制
func parseJsonData(data:NSData) -> [LabelClass] {

        var info = [LabelClass]()
        var error:NSError?

        let jsonResult = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.MutableContainers, error: &error) as? NSDictionary


        if error != nil{
            println(error?.localizedDescription)
        }

        let json = jsonResult?["posts"] as [AnyObject]


        for jsonLoad in json {

            let data = LabelClass()
            data.title = jsonLoan["title"] as String
            data.image = jsonLoan["thumbnail"] as String

            info.append(data)
        }
        return info
   }
EN

回答 1

Stack Overflow用户

发布于 2015-04-11 23:37:56

对于工程中包含的图片,只能使用带named:参数的UIImage函数。

您应该尝试这里使用的方法:Loading/Downloading image from URL on Swift

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29579428

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档