UISearchDisplayController animate reloadData [英] UISearchDisplayController animate reloadData

查看:157
本文介绍了UISearchDisplayController animate reloadData的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在阅读有关 UISearchDisplayController 及其委托的所有文档,但我找不到任何方式



我使用这两种方法:



他们都会返回 YES 找不到任何类似的操作:



我不知道这是否重要,但我使用 NSfetchedResultsController 来填充 UITableView UISearchDisplayController



这是谢谢!

解决方案

当搜索字符串或作用域发生更改时,您为抓取的结果控制器分配一个新的获取请求,因此必须调用 performFetch 得到一个新的结果集。 performFetch 重置控制器的状态,并且不触发任何FRC委托方法。



表视图必须在更改抓取请求后手动更新。在大多数示例程序中,这是通过




  • 在搜索表上调用 reloadData 查看或

  • 中返回 shouldReloadTableForSearchString shouldReloadTableForSearchScope



效果是一样的:搜索表视图重新加载没有动画。 p>

我不认为有任何内置/简单的方法来动态的表视图更新时,搜索谓词更改。但是,您可以尝试以下(这只是一个想法,我没有实际尝试这个自己):




  • fetch请求,复制旧的结果集:

      NSArray * oldList = [[fetchedResultsController fetchedObjects] copy]; 


  • 将新的获取请求分配给FRC并调用 performFetch


  • 获取新的结果集:

     code> NSArray * newList = [fetchedResultsController fetchedObjects]; 


  • 不要调用 reloadData c> newList

    insertRowsAtIndexPaths ,对于删除的对象调用 deleteRowsAtIndexPaths

  • 返回 NO shouldReloadTableForSearchString shouldReloadTableForSearchScope



正如我所说,但我认为它可以工作。


I've been reading all the documentation about UISearchDisplayController and its delegate but I can't find any way to animate the table view when the search criteria change.

I'm using these two methods :

They both return YES but still can't find any way to do something similar to :

I don't know if it's important but I'm using an NSfetchedResultsController to populate the UITableView in the UISearchDisplayController

That's it thanks !

解决方案

When the search string or scope has changed, you assign a new fetch request for the fetched results controller and therefore have to call performFetch to get a new result set. performFetch resets the state of the controller, and it does not trigger any of the FRC delegate methods.

So the table view has to be updated "manually" after changing the fetch request. In most sample programs, this is done by

  • calling reloadData on the search table view, or
  • returning YES from shouldReloadTableForSearchString or shouldReloadTableForSearchScope.

The effect is the same: The search table view is reloaded without animation.

I don't think there is any built-in/easy method to animate the table view update when the search predicate changes. However, you could try the following (this is just an idea, I did not actually try this myself):

  • Before changing the fetch request, make a copy of the old result set:

    NSArray *oldList = [[fetchedResultsController fetchedObjects] copy];
    

  • Assign the new fetch request to the FRC and call performFetch.

  • Get the new result set:

    NSArray *newList = [fetchedResultsController fetchedObjects];
    

  • Do not call reloadData on the search table view.

  • Compare oldList and newList to detect new and removed objects. Call insertRowsAtIndexPaths for the new objects and deleteRowsAtIndexPaths for the removed objects. This can be done by traversing both lists in parallel.
  • Return NO from shouldReloadTableForSearchString or shouldReloadTableForSearchScope.

As I said, this is just an idea but I think it could work.

这篇关于UISearchDisplayController animate reloadData的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆