あなたのコードでは、漠然としたようです。これは、設定されたすべてのイメージをダウンロードしようとするもので、ダウンロードできない場合は、イメージを資産に保存されているイメージプレースホルダに置き換えます。すべての画像がロードされると、同じサイズになります。
これを機能させるには、次の操作を行います。ここにカスタムクラスがあります。あなたのViewController
class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
@IBOutlet weak var tableView: UITableView!
var somePics = ["http://www.something.com/pic1.jpg","http://www.something.net/pic2.jpg","http://www.something.com/pic3.jpg","http://www.something.com/pic4.jpg","http://www.something.net/pic5.jpg"]
var someTitles = ["Picture 1", "Picture 2", "Picture 3", "Picture 4", "Picture 5"]
override func viewDidLoad() {
super.viewDidLoad()
tableView.delegate = self
tableView.dataSource = self
// Do any additional setup after loading the view, typically from a nib.
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
if let cell = tableView.dequeueReusableCellWithIdentifier("SomeCell") as? SomeCell {
var img: UIImage!
let url = NSURL(string: somePics[indexPath.row])!
if let data = NSData(contentsOfURL: url) {
img = UIImage(data: data)
}else {
img = UIImage(named: "somePlaceholderpic")
}
cell.configureCell(img, text: someTitles[indexPath.row])
return cell
} else {
return SomeCell()
}
}
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return somePics.count
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
希望に続いて
class SomeCell: UITableViewCell {
@IBOutlet weak var imgMain: UIImageView!
@IBOutlet weak var lblMain: UILabel!
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
imgMain.layer.cornerRadius = 5.0
imgMain.clipsToBounds = true
}
override func setSelected(selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
func configureCell(image: UIImage, text: String){
imgMain.image = image
lblMain.text = text
}
}
このことができます。 :)
はいあなたは、セルの中に制約を追加する必要はビューとプログラム的ImageViewのフレームを設定する必要はありませんが含まれています。 例:http://postimg.org/image/utqzbrjn1/ –
ストーリーボードでtableviewCellのスクリーンショットを教えてください。あなたが私たちにあなたの制約を示すなら、それは役に立ちます。広告は 'cellForRowAtIndexPath'の下に完全なコードを表示するのもいいでしょう。 –