2015-11-11 33 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 
} 
相關問題