问题
When I try to customise a tableView cell, I found this error.
"Get output frames failed, state 8196"
I just have no idea it is the error from realm or from my customise tableView cell.
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()
}
}
I think it did work when I am using Xcode 9 and Swift 4.1 but now in Xcode 10 it doesn't since it only show me this error and whole blank page of table view.
回答1:
If you are using a Storyboard, you should not call tableView.register
, you should simply set the reuseIdentifier
for your prototype cell in storyboard.
回答2:
If you have a separate .xib file for the cell, you should use:
tableView.register(nib: UINib?, forCellReuseIdentifier: String)
In other words the registration of your cell would be something like that:
self.tableView.register(UINib(nibName: "your cell nib name", bundle: nil), forCellReuseIdentifier: "your cell identifier")
If you have placed your cell in the tableview inside the controller that sits in the Storyboard then you do not need to register your cell, and as @Dávid Pásztor mentioned make sure you add the cell identifier to the cell in the Storyboard
回答3:
This error can be printed in the console when you use Realm even when you intend to only use it offline.
When the app is run in debug mode it will anonymously collect analytics, as stated in this answer: Realm Swift use locally only, however it still tries to connect online
To stop the error, click edit scheme, and add the environment variable REALM_DISABLE_ANALYTICS
, and set it to YES
as shown:
Environment variable screen
来源:https://stackoverflow.com/questions/52710183/get-output-frames-failed-state-8196