2015-11-11 36 views
1

我的控制器上有一个UITableView。当控制器显示页面时,它是焦点。tvOS UITableView在Apple TV上导致错误,但不是模拟器

当焦点行更改时,我想更新下面代码中的UITextView(称为_appText)。

这一切都在模拟器中工作正常,但是当我在苹果电视我收到以下错误上运行:

终止应用程序由于未捕获的异常“NSInternalInconsistencyException”,理由是:“_ignoreFocusUpdateIfNeeded的不应该是重点更新开始。“

我的苹果电视

这里运行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]; 

想不通为什么它在模拟器中工作,而不是苹果电视本身。

+0

您使用的是电脑键盘使用模拟器进行导航?我和你在不同的项目上有同样的错误,但只有当我在模拟器上使用“Apple TV Remote”进行导航时。我不知道如何解决这个问题,但也许事件与此有关。 –

+0

另外,我有这个问题,因为我使用NSAttributedString来显示一个NSHTMLTextDocumentType文档以及..它可能是一个与焦点和UITextView或NSAttributedString相关的错误 –

+0

我也遇到了这个..任何更新它?我不确定发生了什么,但只有当我尝试将HTML放入像您这样的属性字符串时才会发生。 –

回答

1

试试这个:

的Objective-C:

dispatch_async(dispatch_get_main_queue(), ^{ 
    _appText.attributedText=thisString; 
} 

斯威夫特:

dispatch_async(dispatch_get_main_queue()) { 
    _appText.attributedText = thisString 
} 
0

我相信这是你要找的答案: 不知道为什么这是必要的,但我有同样的问题,这确实解决了它... 从香蕉的借口,真正的问题是字符串的转换,而不是任务。

dispatch_async(dispatch_get_main_queue(), ^{ 
    NSAttributedString *thisString=[[NSAttributedString alloc] initWithData:[content dataUsingEncoding:NSUTF8StringEncoding] options:@{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType,NSCharacterEncodingDocumentAttribute: @(NSUTF8StringEncoding)}documentAttributes:nil error:nil]; 
}); 
+0

这可能会回答这个问题,但如果您对代码进行格式化以便可以在不需要侧向滚动的情况下进行阅读,那么这将是一个更好的答案。很高兴看到整个答案没有横向滚动。 – AdrianHHH

0

斯威夫特3

DispatchQueue.main.async { 
    _appText.attributedText = thisString 
} 
相关问题