UISearchDisplayController 动画 reloadData [英] UISearchDisplayController animate reloadData

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

问题描述

我一直在阅读有关 UISearchDisplayController 及其 delegate 的所有文档,但我找不到任何方法在搜索条件更改时为表格视图设置动画.

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 :

他们都返回 YES 但仍然找不到任何方法来做类似的事情:

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

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

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

谢谢!

推荐答案

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

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

  • 在搜索表视图上调用 reloadData,或者
  • shouldReloadTableForSearchStringshouldReloadTableForSearchScope 返回YES.
  • 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];

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

    获取新的结果集:

    NSArray *newList = [fetchedResultsController fetchedObjects];
    

  • 不要在搜索表视图上调用 reloadData.

    正如我所说,这只是一个想法,但我认为它可行.

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

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

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