Ios TableViewCell不';不显示图像视图

Ios TableViewCell不';不显示图像视图,ios,swift,uitableview,Ios,Swift,Uitableview,我在tableView中添加了单元格,我想在任何单元格中显示图像我在我的类“MathViewController”中添加了一个图像数组,我想在每个单元格中显示这些图像。但在任何单元格中都不显示图像。有人知道我的问题吗?我对斯威夫特很陌生,如果你能帮我,那就太好了。 这是我的MathTableViewCell类,用于从故事板获取图像: import UIKit class MathTableViewCell: UITableViewCell{ @IBOutlet weak var ima

我在tableView中添加了单元格,我想在任何单元格中显示图像我在我的类“MathViewController”中添加了一个图像数组,我想在每个单元格中显示这些图像。但在任何单元格中都不显示图像。有人知道我的问题吗?我对斯威夫特很陌生,如果你能帮我,那就太好了。 这是我的MathTableViewCell类,用于从故事板获取图像:

import UIKit
class MathTableViewCell: UITableViewCell{

    @IBOutlet weak var imageCell: UIImageView!
}
下面是MathViewController类:

import UIKit
class MathViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
    @IBOutlet weak var tableController: UITableView!

    let items = ["Calculatorimg" , "ss"]

    override func viewDidLoad() {
        super.viewDidLoad()

        self.tableController.register(UITableViewCell.self, forCellReuseIdentifier: "MathTableViewCell")
        tableController.rowHeight = UITableViewAutomaticDimension
        tableController.estimatedRowHeight = 44
        tableController.delegate = self
        tableController.dataSource = self
    }

    func numberOfSections(in tableView: UITableView) -> Int {
        return 1
    }

    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return items.count
    }

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        if let cell = tableView.dequeueReusableCell(withIdentifier: "MathTableViewCell", for: indexPath)  as? MathTableViewCell{
            cell.imageCell.image = UIImage(named: items[indexPath.row])
            return cell

        }
        return UITableViewCell()
    }

}
这是我的故事板,因为您的单元标识符已设置为MathTableViewCell:
第1部分:为电池创建新的Xib

整个代码是正确的,但忘记将UITableViewCellNib文件注册到tableView中

ViewDidLoad

tableController.register(UINib(nibName: "MathTableViewCell", bundle: nil), forCellReuseIdentifier: "MathTableViewCell")

第2部分:交叉验证CellReuseIdentifier是否正确。

这些图像位于资产或文件夹中。如果这些IMAG位于文件夹中,则您必须提供该图像的扩展名,如“ss.png”@jitendraModi它们位于资产中只需打印项目[indexPath.row]并检查输出内容即可。@nino您是否从故事板创建了单元格?请注意:1)如果您使用的是没有额外笔尖的故事板,请不要注册单元格。2) 删除
cellForRow
中的可选绑定:
let cell=tableView.dequeue。。。(b)作为!MathTableViewCell
以排除设计错误。您如何知道OP使用了额外的nib?我这样做了,但收到了一个错误:无法在名为“MathTableViewCell”的捆绑包中加载nib是您的CellReuseIdentifier=MathTableViewCell?根本没有理由使用额外的nib。@如果为cell创建了新的xib,则需要注册单元nib文件