2017-06-23 41 views
0

私はJSONリンクを持っています。私はテーブルビューにデータを解析するためにAlamofireを使用しています。私はJsonからTextを入手しましたが、イメージは表示されません。 インポートAlamofireImageイメージはテーブルに表示されません。表示

クラスのViewController Alamofire

インポートのUIKit インポート:ここでのUIViewController、UITableViewDelegate、UITableViewDataSource {

@IBOutlet var tableView: UITableView! 
var newsArray = [AnyObject]() 



override func viewDidLoad() { 
    super.viewDidLoad() 

をJSONは

Alamofire.request("http://iccukapp.org/Api_json_format").responseJSON { response in 
     let result = response.result 
     if let dict = result.value as? Dictionary<String,AnyObject>{ 

      if let innerDict = dict["result"]{ 
       self.newsArray = innerDict as! [AnyObject] 
       self.tableView.reloadData() 



      } 
     } 


    } 

} 

呼ばれる。ここでのデータでありますテーブルビューへの負荷

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
    return newsArray.count 
} 

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 
    let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! TableViewCell 

    let title = newsArray[indexPath.row]["title"] 
    cell.newsLabel.text = title as? String 

このURLは私のイメージのURLですが、私は私のJSONを見れば何のurlはイメージ名の前には存在しません。ここに私のjsonリンクhttp://iccukapp.org/Api_json_formatがあります。 イメージアセットのリンクがあります。リンクはこちらhttp://iccukapp.org/assets/admin/images/enter link description here

私のURLに外部リンクを追加する手段はありますか?

let url = NSURL(string: self.newsArray[indexPath.row]["post_iamge"]! as! String) 

    cell.imageVieww.af_setImage(withURL: url! as URL, placeholderImage: #imageLiteral(resourceName: "loadig.gif"), filter: nil, imageTransition: .crossDissolve(0.5), runImageTransitionIfCached: true, completion: nil) 


    return cell 
} 

}

上級者に感謝します。

+0

「self.newsArray」はイメージ名ではありませんimage url.plz check –

答えて

0

あなたの画像の文字列にサーバーのURLを追加する必要があります。

let fullImageUrl = "your serverurl" + (self.newsArray[indexPath.row]["post_iamge"]! as! String) 
let url = URL(string: fullImageUrl) as URL 
cell.imageVieww.af_setImage(withURL: url!, placeholderImage: #imageLiteral(resourceName: "loadig.gif"), filter: nil, imageTransition: .crossDissolve(0.5), runImageTransitionIfCached: true, completion: nil) 
0

イメージアセットのリンクにイメージ名を追加し、そのURLを使用してイメージを表示する必要があると思います。試してみてください

関連する問題