获取输出帧失败,状态8196

时间:2018-10-08 21:12:41

标签: swift uitableview realm

当我尝试自定义tableView单元格时,发现此错误。

  

“获取输出帧失败,状态8196”

我只是不知道这是领域还是我的自定义tableView单元中的错误。

class StudentTableViewController: UITableViewController {

    let realm = try! Realm()
    var student: Results<StudentName>?
    var selectedClass: ClassName? {
        didSet {
            load()
        }
    }
    var selected: String = ""

    override func viewDidLoad() {
        super.viewDidLoad()
        navigationController?.title = selected
        tableView.register(StudentTableViewCell.self, forCellReuseIdentifier: "studentName")
    }

    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return student?.count ?? 1
    }

    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "studentName", for: indexPath) as! StudentTableViewCell
        cell.name.text = student?[indexPath.row].name ?? "There are no student in this class"
        cell.number.text = "\(student?[indexPath.row].studentNumber ?? 0)"
        return cell
    }
    func load() {
        student = selectedClass?.studentNames.sorted(byKeyPath: "studentNumber", ascending: true)
        tableView.reloadData()
    }
}

我认为当我使用Xcode 9和Swift 4.1时它确实起作用了,但是现在在Xcode 10中却没有,因为它只向我显示此错误和表格视图的整个空白页。

3 个答案:

答案 0 :(得分:1)

如果使用情节提要,则不应调用tableView.register,而只需为情节提要中的原型单元设置reuseIdentifier

答案 1 :(得分:0)

如果该单元格有单独的.xib文件,则应使用:

tableView.register(nib: UINib?, forCellReuseIdentifier: String)

换句话说,您的单元格的注册将是这样的:

self.tableView.register(UINib(nibName: "your cell nib name", bundle: nil), forCellReuseIdentifier: "your cell identifier")

如果您已将单元格放置在情节提要中位于控制器内的表格视图中,则无需注册您的单元格,并且如@DávidPásztor所述,请确保将单元格标识符添加到情节提要中的单元格< / p>

答案 2 :(得分:0)

使用Realm时,即使打算仅脱机使用它,也可以在控制台中打印该错误。

以调试模式运行该应用程序时,它将匿名收集分析数据,如以下答案所述:Realm Swift use locally only, however it still tries to connect online

要停止该错误,请单击编辑方案,然后添加环境变量REALM_DISABLE_ANALYTICS,并将其设置为YES,如下所示:

Environment variable screen