私はUITableViewController
をストーリーボードではなくXIBで使用しようとしており、デフォルトのスタイルはUITableViewCellStyleDefault
です。私はimageView
のcornerRadius
をimageView
の幅/ 2に設定したいと思っていますが、cellForRowAtIndexPath()
の間にはimageView
は0,0,0,0です。cellForRowAtIndexPathの間にimageViewのフレームサイズを取得するにはどうすればよいですか?
フレームがサブビューに追加されるまで、更新されないことがわかりました。
imageView.frame.size.width
を入手するにはどうすればよいですか? UITableView
が正しく行を示しているが、cornerRadius
は、あなたの目標を達成するために0
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("ContactCell", forIndexPath: indexPath)
// Set Image
cell.imageView?.image = UIImage.init(imageLiteral: "\(indexPath.row).jpg")
// FOLLOWING DOESNT WORK imageView is 0,0,0,0
cell.imageView?.layer.cornerRadius = cell.imageView!.frame.size.width/2
cell.imageView?.clipsToBounds = true
cell.imageView?.layer.masksToBounds = true
// Set Label
let name:String = contactsArray![indexPath.row] as! String
cell.textLabel!.text = name
return cell
}
あなたのimageViewにプレースホルダ画像または高さ/幅の制約を指定しましたか? – Happiehappie
いいえ、これはXIBにあるので、私はプロトタイプのセルを使用することはできませんし、ImもカスタムセルXIBを使用していません。私がしたのは、viewDidLoad:tableView.registerClass(UITableViewCell.self、forCellReuseIdentifier: "ContactCell")のデフォルトのUITableViewCellを登録することでした。 XIBで何もできませんでした。なぜなら、それはストーリーボードではないXIBなので、私はそれができないからです。私はおそらく自分のUITableViewCellを作成し、いくつかのデフォルトを与える必要があります。 – KevinS
私は 'UIImage.init(imageLiteral:" \(indexPath.row).jpg ")'を使用したことは一度もありません。私はいつも 'UIImage(name:" \(indexPath.row).jpg ")'を使用します。 –