2014-11-21 52 views
1

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

回答

1

請修改您的方法,並檢查:

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! 
} 
相關問題