【发布时间】:2015-11-11 19:34:15
【问题描述】:
我的控制器上有一个 UITableView。当控制器显示页面时,它处于焦点。
当焦点行发生变化时,我想在下面的代码中更新一个 UITextView(称为 _appText)。
这一切在模拟器中运行良好,但是当我在 Apple TV 上运行时出现以下错误:
由于未捕获的异常“NSInternalInconsistencyException”而终止应用,原因:“_ignoreFocusUpdateIfNeeded 在焦点更新开始时不应为 YES。”
我在 Apple TV 上运行 tvOS 9.01 版
代码如下:
- (void)tableView:(UITableView *)tableView didUpdateFocusInContext(UITableViewFocusUpdateContext *)contextwithAnimationCoordinator:(UIFocusAnimationCoordinator*)coordinator{
NSInteger ourRow=context.nextFocusedIndexPath.row;
NSString *path =[[NSBundle mainBundle] pathForResource:[_appIconNames objectAtIndex:ourRow] ofType:@"html"];
NSString *content = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:NULL];
NSAttributedString *thisString=[[NSAttributedString alloc] initWithData:[content dataUsingEncoding:NSUTF8StringEncoding] options:@{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType,NSCharacterEncodingDocumentAttribute: @(NSUTF8StringEncoding)}documentAttributes:nil error:nil];
_appText.attributedText=thisString;
}
导致错误的行是:
NSAttributedString *thisString=[[NSAttributedString alloc] initWithData:[content dataUsingEncoding:NSUTF8StringEncoding] options:@{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType,NSCharacterEncodingDocumentAttribute: @(NSUTF8StringEncoding)}documentAttributes:nil error:nil];
无法弄清楚为什么它在模拟器中有效,但在 Apple TV 本身中无效。
【问题讨论】:
-
您是否使用计算机键盘在模拟器中导航?我在另一个项目中遇到了与您相同的错误,但只有当我在模拟器上使用“Apple TV Remote”进行导航时。我还不知道如何解决这个问题,但可能与此有关。
-
另外,我遇到了这个问题,因为我也在使用 NSAttributedString 来显示 NSHTMLTextDocumentType 文档。这可能是与焦点和 UITextView 或 NSAttributedString 相关的错误
-
我也遇到了这个问题。有什么更新吗?我不确定发生了什么,但只有当我试图将 HTML 放入像你这样的属性字符串时才会发生这种情况。
标签: objective-c uitableview tvos apple-tv