当Voiceover打开时,我试图加载一个原型单元时遇到了一个问题。应用程序崩溃,我收到错误消息
Assertion failure in -[UITableView _createPreparedCellForGlobalRow:withIndexPath:]
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:'
这仅在VoiceOver打开时发生,否则应用程序运行正常。有什么帮助吗?
发布于 2012-10-17 15:29:10
我不确定我是不是碰巧弄对了,但这对我来说是可行的。在UITableViewDataSource
中
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
[...]
UITableViewCell *standardCell;
if (UIAccessibilityIsVoiceOverRunning()) {
standardCell = [tableView dequeueReusableCellWithIdentifier:@"VO Cell"];
} else {
standardCell = [tableView dequeueReusableCellWithIdentifier:@"Regular Cell"];
}
//Configure the cell
[...]
return standardCell;
}
我相信,如果出于性能原因关闭了VoiceOver,那么iOS会缓存没有可访问性属性的单元格。因此,您使用的默认标识符可能与不具有这些属性的缓存单元相关。当VoiceOver打开时,当iOS尝试将这些单元格出队时,它找不到其中的属性并中断。通过使用不同的标识符,您可以强制iOS在VO打开时缓存新的单元。
同样,这只是一个假设,我正在进行,但情况是,当我以这种方式将信元出队时,我不会得到这个问题。但是,如果您确实像我提到的那样将它们出队,则必须注意可能出现的错误:
如果您要将其标识符在.xib文件或Storyboard中设置的单元出列,如下图所示,则必须使用VO重用标识符设置另一个原型单元。
https://stackoverflow.com/questions/8264563
复制