我试着写的应用程序,数据可以显示的形式Json和显示在集合视图,但问题是只有文本可以显示,而不是图片。有没有人能帮上忙,或者给我一些建议?
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 }
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
}发布于 2015-04-11 23:37:56
对于工程中包含的图片,只能使用带named:参数的UIImage函数。
您应该尝试这里使用的方法:Loading/Downloading image from URL on Swift
https://stackoverflow.com/questions/29579428
复制相似问题