Ios Tableviewcell未更改背景图像

Ios Tableviewcell未更改背景图像,ios,swift,uitableview,Ios,Swift,Uitableview,请注意此代码 func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCellWithIdentifier("commentCell", forIndexPath: indexPath) as! CommentTableViewCell cell.c

请注意此代码

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)))

由于某种原因,同一代码在另一个单元格上不起作用。我似乎找不到原因,所以我希望你们中的一个人能发现一些我看不到的东西。

检查UITableViewCell的.h文件。我找到了这个

UITableViewStylePlain中的单元格默认为零,UITableViewStyleGrouped中的单元格默认为非零。背景视图将添加为所有其他视图后面的子视图

@property (nonatomic, retain) UIView *backgroundView;
通常,我们不做任何建议:

将ImageView添加到单元格。 将ImageView的帧设置为等于cell.contentView.bounds 控制自己的行为。 做你想做的!