Ios 使用自定义UITableViewCell时,dequeueReusableCell(标识符:)中出现SIGABRT错误

Ios 使用自定义UITableViewCell时,dequeueReusableCell(标识符:)中出现SIGABRT错误,ios,swift,uitableview,sigabrt,Ios,Swift,Uitableview,Sigabrt,我正在构建一个包含多个场景的应用程序,每个场景中都有一个自定义单元格的表视图。我让主屏幕表格视图正常工作,然后从自定义单元格切换到新场景。当它分段时,我的第二个视图控制器崩溃 这是我的视图控制器代码 import UIKit class QuestionViewController: UIViewController { @IBOutlet weak var questionLabel: UILabel! @IBOutlet weak var submitButton: UI

我正在构建一个包含多个场景的应用程序,每个场景中都有一个自定义单元格的表视图。我让主屏幕表格视图正常工作,然后从自定义单元格切换到新场景。当它分段时,我的第二个视图控制器崩溃

这是我的视图控制器代码

import UIKit

class QuestionViewController: UIViewController {

    @IBOutlet weak var questionLabel: UILabel!
    @IBOutlet weak var submitButton: UIButton!
    @IBOutlet weak var qTableView: UITableView!


    var answers : [QuestionOption] = []


    override func viewDidLoad() {
        super.viewDidLoad()
        answers = [QuestionOption(text: "test"), QuestionOption(text: "test"), QuestionOption(text: "test"), QuestionOption(text: "test")]
        qTableView.delegate = self
        qTableView.dataSource = self
        submitButton.setTitle("Submit", for: .normal)
        questionLabel.text = "test question"
    }


}

extension QuestionViewController: UITableViewDataSource, UITableViewDelegate{

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

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let a = answers[indexPath.row]
        let cell = qTableView.dequeueReusableCell(withIdentifier: "QuestionOptionCell") as! QuestionOptionCell

        cell.setOption(option: a)

        return cell
    }

}
这是我的手机代码

import UIKit

class QuestionOptionCell: UITableViewCell {

    @IBOutlet weak var cellTitle: UILabel!

    func setOption(option: QuestionOption){
        cellTitle.text = option.text
    }

}
这是我的QuestionOption类代码

import Foundation
import UIKit

class QuestionOption{
    var text: String

    init(text: String){
        self.text = text
    }
}
事故日志

2019-02-20 14:33:28.394695-0800 iQuiz[8935:822409] *** NSForwarding: warning: object 0x7fd608407c40 of class 'iQuiz.QuestionOption' does not implement methodSignatureForSelector: -- trouble ahead
Unrecognized selector -[iQuiz.QuestionOption initWithCoder:]
2019-02-20 14:33:28.395281-0800 iQuiz[8935:822409] Unrecognized selector -[iQuiz.QuestionOption initWithCoder:]
这是我的故事板,如果有帮助的话

我已确保我的标识符匹配,并且没有任何无关或未连接的插座,这是我可以在网上找到的解决此问题的唯一方法。

需要检查的事项:

  • 验证“QuestionOptionCell”确实是单元的重用标识符
  • 验证所选单元格类型是否为
    QuestionOptionCell
  • 在cellForRowAt中,使用
    tableView.dequeueReusableCell
    而不是
    qTableView.dequeueReusableCell
否则,请与我们共享崩溃日志。

要检查的事项:

  • 验证“QuestionOptionCell”确实是单元的重用标识符
  • 验证所选单元格类型是否为
    QuestionOptionCell
  • 在cellForRowAt中,使用
    tableView.dequeueReusableCell
    而不是
    qTableView.dequeueReusableCell

否则,请与我们共享崩溃日志。

崩溃日志说明
QuestionOption
必须是
NSObject
的子类,并采用
NSCoding
,在这种情况下,这是过分的。实际上,一个结构就足够了

您可以通过删除
QuestionOptionCell

并通过替换直接在
cellForRowAt
中设置值

cell.setOption(option: a)


崩溃日志显示,
QuestionOption
必须是
NSObject
的子类,并采用
NSCoding
,在这种情况下,这样做太过分了。实际上,一个结构就足够了

您可以通过删除
QuestionOptionCell

并通过替换直接在
cellForRowAt
中设置值

cell.setOption(option: a)


单元格的类是否设置为
QuestionOptionCell
?能否将示例项目放在Dropbox或Github上?请添加您的控制台崩溃log@qtngo@kjoe I将其添加到原始问题中。单元格的类是否设置为
QuestionOptionCell
?能否将示例项目放在Dropbox或Github上?请将其添加到控制台崩溃中log@qtngo @kjoe我将其添加到原始问题中,我没有看到重用标识符,但我确实看到了标识符,它被设置为“QuestionOptionCell”,我没有看到重用标识符,但我确实看到了标识符,它被设置为“QuestionOptionCell”,修复了它。我不明白为什么它适用于我的另一个tableview,但不适用于这个。有什么想法吗?没有。正如在另一个答案中提到的,您应该始终在
cellForRow
中使用传递的
tableView
参数,而不是属性
qTableView
。是的,我也解决了这个问题。谢谢你帮我修好了。我不明白为什么它适用于我的另一个tableview,但不适用于这个。有什么想法吗?没有。正如在另一个答案中提到的,您应该始终在
cellForRow
中使用传递的
tableView
参数,而不是属性
qTableView
。是的,我也解决了这个问题。谢谢你的帮助
cell.cellTitle.text = a.text