Ios swift-自定义UITableViewCell不';t显示故事板中添加的内容

Ios swift-自定义UITableViewCell不';t显示故事板中添加的内容,ios,swift,uitableview,cocoa-touch,Ios,Swift,Uitableview,Cocoa Touch,我决定用xib声明一个自定义UITableViewCell类,以便更容易控制单元格的背景,因为它需要根据单元格在表中的位置而有所不同 这很好,但是当我尝试在故事板中的自定义单元格中添加额外视图时,它们不会显示,只显示原始自定义单元格 这是我的自定义单元格类: class GlTableViewCell: UITableViewCell { override func awakeFromNib() { super.awakeFromNib() // In

我决定用xib声明一个自定义UITableViewCell类,以便更容易控制单元格的背景,因为它需要根据单元格在表中的位置而有所不同

这很好,但是当我尝试在故事板中的自定义单元格中添加额外视图时,它们不会显示,只显示原始自定义单元格

这是我的自定义单元格类:

class GlTableViewCell: UITableViewCell {


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


        let bgView: UIView = UIView()
        bgView.backgroundColor = .clear

        self.backgroundView = bgView
        self.backgroundColor = .clear

    }

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

        // Configure the view for the selected state
    }

    func isFirst() {

        //Top

        let topLeftCornerImageView = self.viewWithTag(101) as! UIImageView

        let topLineImageView = self.viewWithTag(102) as! UIImageView

        let topRightCornerImageView = self.viewWithTag(103) as! UIImageView

        topLeftCornerImageView.image = UIImage(named: "cellTopLeftCorner")

        topLineImageView.image = UIImage(named: "cellTopLine")

        topRightCornerImageView.image = UIImage(named: "cellTopRightCorner")



        //Bottom

        let bottomLeftCornerImageView = self.viewWithTag(201) as! UIImageView

        let bottomLineImageView = self.viewWithTag(202) as! UIImageView

        let bottomRoghtCornerImageView = self.viewWithTag(203) as! UIImageView

        bottomLeftCornerImageView.image = UIImage(named: "cellLeftLine")

        bottomLineImageView.image = UIImage(named: "cellBackgroundFill")

        bottomRoghtCornerImageView.image = UIImage(named: "cellRightLine")

    }

    func isLast() {


        //Top

        let topLeftCornerImageView = self.viewWithTag(101) as! UIImageView

        let topLineImageView = self.viewWithTag(102) as! UIImageView

        let topRightCornerImageView = self.viewWithTag(103) as! UIImageView

        topLeftCornerImageView.image = UIImage(named: "cellLeftLine")

        topLineImageView.image = UIImage(named: "cellBackgroundFill")

        topRightCornerImageView.image = UIImage(named: "cellRightLine")



        //Bottom

        let bottomLeftCornerImageView = self.viewWithTag(201) as! UIImageView

        let bottomLineImageView = self.viewWithTag(202) as! UIImageView

        let bottomRoghtCornerImageView = self.viewWithTag(203) as! UIImageView

        bottomLeftCornerImageView.image = UIImage(named: "cellBottomLeftCorner")

        bottomLineImageView.image = UIImage(named: "cellBottomLine")

        bottomRoghtCornerImageView.image = UIImage(named: "cellBottomRightCorner")
    }

    func isSingle() {

        //Top

        let topLeftCornerImageView = self.viewWithTag(101) as! UIImageView

        let topLineImageView = self.viewWithTag(102) as! UIImageView

        let topRightCornerImageView = self.viewWithTag(103) as! UIImageView

        topLeftCornerImageView.image = UIImage(named: "cellTopLeftCorner")

        topLineImageView.image = UIImage(named: "cellTopLine")

        topRightCornerImageView.image = UIImage(named: "cellTopRightCorner")


        //Bottom

        let bottomLeftCornerImageView = self.viewWithTag(201) as! UIImageView

        let bottomLineImageView = self.viewWithTag(202) as! UIImageView

        let bottomRoghtCornerImageView = self.viewWithTag(203) as! UIImageView

        bottomLeftCornerImageView.image = UIImage(named: "cellBottomLeftCorner")

        bottomLineImageView.image = UIImage(named: "cellBottomLine")

        bottomRoghtCornerImageView.image = UIImage(named: "cellBottomRightCorner")



    }

    func isMiddle() {
        let topLeftCornerImageView = self.viewWithTag(101) as! UIImageView

        let topLineImageView = self.viewWithTag(102) as! UIImageView

        let topRoghtCornerImageView = self.viewWithTag(103) as! UIImageView

        let bottomLeftCornerImageView = self.viewWithTag(201) as! UIImageView

        let bottomLineImageView = self.viewWithTag(202) as! UIImageView

        let bottomRightCornerImageView = self.viewWithTag(203) as! UIImageView



        topLeftCornerImageView.image = UIImage(named: "cellLeftLine")

        topLineImageView.image = UIImage(named: "cellBackgroundFill")

        topRoghtCornerImageView.image = UIImage(named: "cellRightLine")


        bottomLeftCornerImageView.image = UIImage(named: "cellLeftLine")

        bottomLineImageView.image = UIImage(named: "cellBackgroundFill")

        bottomRightCornerImageView.image = UIImage(named: "cellRightLine")




    }

}
这是我的桌子:

override func viewDidLoad() {
        super.viewDidLoad()

        updateLabels()

        tableView.register(UINib(nibName: "GlTableViewCell", bundle: nil), forCellReuseIdentifier: "ProductCell")
    }

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {


        let cell = tableView.dequeueReusableCell(withIdentifier: "ProductCell", for: indexPath) as! GlTableViewCell

        cell.isSingle()
        return cell


..

我做错了什么?

您的程序是否在
让topLeftCornerImageView=self.viewWithTag(101)as上崩溃了!UIImageView
?不,不需要,只要我的tableview控制器中有:tableview.register(UINib(nibName:“GlTableViewCell”,bundle:nil),forCellReuseIdentifier:“ProductCell”)