0
請注意此代碼。Tableviewcell不會更改背景圖片
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("commentCell", forIndexPath: indexPath) as! CommentTableViewCell
cell.commentText?.text = comments![indexPath.row]
if let objectId = yak?["user"].objectId {
let commentor = commentorIds[indexPath.row]
if commentor == objectId {
cell.commentText.textColor = UIColor(red: 136.0/255, green: 135.0/255, blue: 134.0/255, alpha: 1)
let image = UIImage(named: "eh")
cell.backgroundView = UIImageView(image: image?.resizableImageWithCapInsets(UIEdgeInsets(top: 20, left: 20, bottom: 50, right: 50)))
} else {
cell.commentText.textColor = UIColor.whiteColor()
let image = UIImage(named: "whatsthatnow")
cell.backgroundView = UIImageView(image: image?.resizableImageWithCapInsets(UIEdgeInsets(top: 20, left: 20, bottom: 20, right: 100)))
}
}
cell.layoutMargins = UIEdgeInsetsZero
//cell.backgroundView = UIImageView(image: UIImage(named: "goodbg"))
return cell
}
但是,這對於特定的視圖控制器來說工作得很好。請注意這段代碼片段。
func tableViewOld(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!, object: PFObject!) -> UITableViewCell! {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! TableViewCell
let image = UIImage(named: "eh")
cell.backgroundView = UIImageView(image: image?.resizableImageWithCapInsets(UIEdgeInsets(top: 20, left: 20, bottom: 50, right: 50)))
此相同的代碼由於某種原因在另一個單元上不起作用。我似乎無法找到它的原因,所以我希望你們中的一個人能夠發現我不能做的事情。