The UIImageView
is not showing the image up in my custom UITableViewCell
.
Can't figure out why, I have tried both methods of setting the Image
property it in the Interface Builder
and then tried setting up an IBOutlet
and setting the .image
property.
None seem to work. Why is this happening to me?!?!
Class with TableViewDataSource
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell = tableView.dequeueReusableCellWithIdentifier("LatestMessageCell") as LatestMessageCell
cell.avatarImageView.image = UIImage(named: "Logo")
return cell
}
Custom Cell Class
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
}
}
Pls modify your Method and check:
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!
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.