UIImageView未在自定义UITableViewCell中显示图像

问题描述:

UIImageView未在我的自定义UITableViewCell中显示图像。UIImageView未在自定义UITableViewCell中显示图像

想不通为什么,我已经尝试设置Image特性它在Interface Builder这两种方法,然后试图建立一个IBOutlet并设置.image财产。

似乎没有工作。为什么这发生在我身上?!?!

类具有TableViewDataSource

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 

    var cell = tableView.dequeueReusableCellWithIdentifier("LatestMessageCell") as LatestMessageCell 

    cell.avatarImageView.image = UIImage(named: "Logo") 

    return cell 
} 

自定义单元格类

class LatestMessageCell: UITableViewCell { 

@IBOutlet weak var cardBackgroundView: UIView! 

@IBOutlet weak var avatarImageView: UIImageView! 

@IBOutlet weak var usernameLabel: UILabel! 

@IBOutlet weak var messageLabel: UILabel! 

override func awakeFromNib() { 
    super.awakeFromNib() 
    // Initialization code 

    cardBackgroundView.layer.cornerRadius = 4 
    cardBackgroundView.layer.shadowColor = UIColor.blackColor().CGColor 
    cardBackgroundView.layer.shadowOffset = CGSize(width: 0, height: 2) 
    cardBackgroundView.layer.shadowOpacity = 0.3 
    cardBackgroundView.layer.shadowRadius = 5 
} 

override func setSelected(selected: Bool, animated: Bool) { 
    super.setSelected(selected, animated: animated) 

    // Configure the view for the selected state 
} 

}

+1

我会说: •检查插座是否设置正确 •检查图像是否已加载(可能是错误的图像名称?) – DeFrenZ 2014-11-21 12:12:14

请修改您的方法,并检查:

let simpleTableIdentifier = "TableViewCell"; 

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell 
{ 

     var cell:LatestMessageCell? = tableView.dequeueReusableCellWithIdentifier(simpleTableIdentifier) as? LatestMessageCell 

     if (cell == nil) 
     { 
      let nib:Array = NSBundle.mainBundle().loadNibNamed("LatestMessageCell", owner: self, options: nil) 
      cell = nib[0] as? LatestMessageCell 
     } 

     cell!.avatarImageView.image = UIImage(named: "Logo") 

     return cell! 
}