[英]fatal error: unexpectedly found nil while unwrapping an Optional value in Tableview
I had implemented UITableView
with custom cell.It works fine. 我已经用自定义单元实现了UITableView
,效果很好。
Tableviewcell have 3 textfields in every cell. Tableviewcell在每个单元格中都有3个文本字段。
I try to access all cell on submit button. 我尝试访问“提交”按钮上的所有单元格。
But app is crash due to access non-visible cell. 但是由于访问不可见的单元格,应用程序崩溃了。
How can I got all cell's all 3 textfield values even they are not visible. 我如何获得所有单元格的所有3个文本字段值,即使它们不可见。
Thank you, 谢谢,
UITableView
's cellForRowAtIndexPath
method will return nil if cell not visible. 如果单元格不可见,则UITableView
的cellForRowAtIndexPath
方法将返回nil。 You should check for this, and perform only data source changes if so: 您应该检查一下,如果这样,则仅执行数据源更改:
if let cell_note = self.tbl.cellForRowAtIndexPath(NSIndexPath(forRow: 0, inSection: 4)) as? NotesCell
{
// do something with your data source
// do something with cell_note that already loaded on screen
}
else
{
// do something with your data source
// your cell didn't loaded yet
// you should only prepare fresh information in your data source for delegate method tableView(_:cellForRowAtIndexPath:)
}
Note that if you have same data source changes for both cases (as usual in fact), you need move them out of this check 请注意,如果两种情况下的数据源更改都相同(实际上与往常一样),则需要将其移出此检查
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.