1
我已經看到這個問題很多地方,但尚未遇到一個適合我的解決方案。我有一個自定義UITableViewCell
,其中我已經放置了一個UIImageView
。圖像視圖應該擁抱單元格的右側(來自xib文件的約束)。下面是細胞是如何創建,然後格式化代碼:自定義UIImageView通過UITableViewCell重新對齊
class PlaylistCell: UITableViewCell {
@IBOutlet var imView: UIImageView?
@IBOutlet var label: UILabel?
var playlist:SPTPartialPlaylist? {
didSet {
self.configure()
}
}
func configure()
{
self.imView?.clipsToBounds = true
self.label?.text = self.playlist?.name
let uri = (self.playlist?.images[0] as! SPTImage).imageURL
dispatch_async(dispatch_get_main_queue(), {
let data = NSData(contentsOfURL: uri!)
if (data != nil) {
self.imView?.image = UIImage(data: data!)
self.layoutSubviews()
}
})
}
而且在我ViewController
已在它的表視圖:
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
let cell = tableView.dequeueReusableCellWithIdentifier("PlaylistCell") as! PlaylistCell
cell.playlist = self.playlists[indexPath.row]
cell.imView?.image = UIImage(named: "placeholder")
return cell
}
一切正確加載和細胞看起來不錯,但當其中一個單元格被觸摸時,圖像捕捉到單元格的左側並縮小尺寸。有誰知道爲什麼會發生這種情況? (PS我一直在使用SDWebImage
嘗試和同一個問題隨之而來)
發佈一些截圖 –