ios - UISearchDisplayController 中结果显示延迟 5s
<p><p>我的 <code>UISearchDisplayController</code> 通过 <code>NSOperationQueue</code> 执行异步搜索。</p>
<p>但是,在 <code>NSOperation</code> 调用 <code></code> 大约 5 秒后,结果表才会在视觉上更新。</p>
<pre><code>- (BOOL) searchDisplayController:(UISearchDisplayController*)controller shouldReloadTableForSearchString:(NSString*)searchString
{
;
NSInvocationOperation *op = [[ initWithController:controller searchTerm:searchString] autorelease];
;
return NO;
}
</code></pre>
<p>我的 CustomerSearchOperation 像这样更新 tableView:</p>
<pre><code>- (void) main
{
// perform search
;
;
}
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>问题是 UI 更新必须发生在主线程上,并且 <code>reloadData</code> 是通过 <code>NSOperationQueue</code> 从后台线程调用的。</p>
<p>你可以使用<code>NSObject</code>方法<a href="http://developer.apple.com/library/ios/#DOCUMENTATION/Cocoa/Reference/Foundation/Classes/NSObject_Class/Reference/Reference.html#//apple_ref/occ/instm/NSObject/performSelectorOnMainThread%3awithObject%3awaitUntilDone%3a" rel="noreferrer noopener nofollow">performSelectorOnMainThread:withObject:waitUntilDone:</a>以确保此类更新发生在主线程上。</p>
<pre><code>- (void) main
{
// perform search
;
[sdc.searchResultsTableView performSelectorOnMainThread:@selector(reloadData)
withObject:nil
waitUntilDone:NO];
}
</code></pre></p>
<p style="font-size: 20px;">关于ios - UISearchDisplayController 中结果显示延迟 5s,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/4942718/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/4942718/
</a>
</p>
页:
[1]