简体   繁体   English

致命错误:在Tableview中展开Optional值时意外发现nil

[英]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. 如果单元格不可见,则UITableViewcellForRowAtIndexPath方法将返回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.

相关问题 致命错误:选择tableView单元格时,在展开可选值swift时意外发现nil - fatal error: unexpectedly found nil while unwrapping an Optional value swift When Selecting tableView Cells 快速搜索栏和表格视图-致命错误:在展开可选值时意外发现nil - swift searchbar and tableview - fatal error: unexpectedly found nil while unwrapping an optional value 它在tableview的cellforrowatindexpath中崩溃,表示:“致命错误:在展开可选值时意外发现nil” - It crashes in cellforrowatindexpath of tableview , says : “fatal error: unexpectedly found nil while unwrapping an Optional value” 致命错误:解开可选值(lldb)时意外发现nil - fatal error: unexpectedly found nil while unwrapping an Optional value (lldb) 快速致命错误:解开Optional值时意外发现nil - swift fatal error: unexpectedly found nil while unwrapping an Optional value Swift致命错误:解开Optional值时意外发现nil - Swift fatal error: unexpectedly found nil while unwrapping an Optional value 致命错误:展开一个可选值(lldb)时意外发现nil - Fatal error: Unexpectedly found nil while unwrapping an Optional value (lldb) UIToolbar的“致命错误:解开可选值时意外发现为零” - 'fatal error: unexpectedly found nil while unwrapping an Optional value' for UIToolbar 致命错误:在 UITableViewCell 中解包可选值时意外发现 nil - fatal error: unexpectedly found nil while unwrapping an Optional value in UITableViewCell 致命错误:解开可选值(lldb)时意外发现nil - fatal error: unexpectedly found nil while unwrapping an Optional value (lldb)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM