ios 5原型单元和VoiceOver问题

Pau*_*boy 6 iphone ipad ios ios5

在启用画外音时尝试加载原型单元时遇到问题.应用程序崩溃,我得到错误

Assertion failure in -[UITableView _createPreparedCellForGlobalRow:withIndexPath:]

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:'
Run Code Online (Sandbox Code Playgroud)

这仅在VoiceOver打开时发生,否则应用程序运行正常.有帮助吗?

小智 0

我不确定我是否偶然做对了,但这对我来说很有效。在里面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;

}
Run Code Online (Sandbox Code Playgroud)

我相信如果出于性能原因关闭 VoiceOver,iOS 会缓存没有辅助功能属性的单元格。因此,您使用的默认标识符可能与不具有这些属性的缓存单元格相关。当 VoiceOver 打开并且 iOS 尝试将这些 Cell 出队时,它找不到其中的属性并中断。通过使用不同的标识符,您可以强制 iOS 在 VO 打开时缓存新的 Cell。

再说一遍,这只是我所做的一个假设,但实际情况是,当我以这种方式使单元出队时,我不会遇到此问题。但是,如果您按照我提到的方式将它们出队,则必须注意可能出现的错误:

如果您要使在 .xib 文件或 Storyboard 中设置了标识符的单元格出队,如下图所示,则必须使用 VO 重用标识符设置另一个原型单元格。 重用 Interface Builder 中设置的标识符