http://yuu.1000quu.com/use_a_custom_cell_in_swift
このサイトを参考にして
swift
1//ViewController.swift 2import UIKit 3 4class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource { 5 let strArray = [String]() 6 let imageNames = ["test.png"] 7 override func viewDidLoad() { 8 super.viewDidLoad() 9 } 10 11 func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 12 return imageNames.count 13 } 14 15 /// セルに値を設定するデータソースメソッド(必須) 16 func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 17 // セルを取得 18 let cell = tableView.dequeueReusableCell(withIdentifier: "cells") as! CustomTableViewCell 19 20 // セルに値を設定 21 cell.setCell(IconImage: imageNames[indexPath.row]) 22 return cell 23 } 24}
swift
1//CustomTableViewCell.swift 2import UIKit 3 4class CustomTableViewCell: UITableViewCell { 5 @IBOutlet weak var cellimg: UIImageView! 6 7 override func awakeFromNib() { 8 super.awakeFromNib() 9 } 10 11 override func setSelected(_ selected: Bool, animated: Bool) { 12 super.setSelected(selected, animated: animated) 13 } 14 func setCell(IconImage: String) { 15 cellimg.image = UIImage(named: IconImage) 16 } 17}
このような感じでXcode内のtest.pngの画像ファイルをセルに表示することはできたのですが、インターネット上にある画像を表示するにはどのようにすれば良いのでしょうか
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/04/25 03:56