Ios 触摸UITableViewCell时自定义UIImageView重新对齐

Ios 触摸UITableViewCell时自定义UIImageView重新对齐,ios,iphone,uitableview,uiimageview,Ios,Iphone,Uitableview,Uiimageview,我已经在很多地方看到过这个问题,但还没有找到一个适合我的解决方案。我有一个自定义的UITableViewCell,其中放置了一个UIImageView。图像视图应该紧靠单元格的右侧(带有来自xib文件的约束)。以下是如何创建单元格并对其进行格式化的代码: class PlaylistCell: UITableViewCell { @IBOutlet var imView: UIImageView? @IBOutlet var label: UILabel? var playlist:SPT

我已经在很多地方看到过这个问题,但还没有找到一个适合我的解决方案。我有一个自定义的
UITableViewCell
,其中放置了一个
UIImageView
。图像视图应该紧靠单元格的右侧(带有来自xib文件的约束)。以下是如何创建单元格并对其进行格式化的代码:

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()
        }
    })
}
在包含表格视图的my
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
,同样的问题接踵而至)


您可以尝试将其添加到您的播放列表单元格中吗

override func didMoveToSuperview() {
     self.layoutIfNeeded()
}

你能试着把它添加到你的手机里吗

override func didMoveToSuperview() {
     self.layoutIfNeeded()
}

发布一些截图发布一些截图