iphone - 动画添加/删除 UISearchBar 到/从 UITableView tableViewHeader

标签 iphone objective-c uitableview uisearchbar

我有一个 UITableViewController 的子类。我有代码可以在我的 tableView 的 tableHeaderView 中添加/删除 UISearchBar。这是我必须执行这些任务的代码:

self.tableView.tableHeaderView = uiSearchBar; //Make the search bar appear
self.tableView.tableHeaderView = nil; //Make the search bar disappear

问题是我希望添加/删除 UISearchBar 是动画的;当我添加它时从顶部滑入 View ,然后当我删除它时向上滑动并滑出 View ,而不是仅仅出现和消失。有什么建议吗?

谢谢。

最佳答案

我终于弄明白了。结果很简单。我没有将 UISearchBar 添加到表头,而是使用动画 UITableViewRowAnimationTop 将它插入到表的第一个单元格中,并使用相同的方法将其删除。这导致条从顶部滑入和滑出。这是使栏出现的代码:

NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
[self.baseUiTableView insertRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationTop];
[self.baseUiTableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:YES];

下面是删除搜索栏的代码:

[uiSearchBar resignFirstResponder];
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
[self.baseUiTableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationTop];

关于iphone - 动画添加/删除 UISearchBar 到/从 UITableView tableViewHeader,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1319567/

相关文章:

iphone - 如何在 iphone 的应用程序购买中实现每月订阅?

ios - 通过 UIAlertview 处理推送通知

ios - UITextField 键盘。如何禁用强制触摸?

ios - 使用简洁形式的 NSManagedObjectID URI?

objective-c - 为什么我似乎必须在 iOS 应用程序委托(delegate)中强制转换 window.rootViewController?

objective-c - 为什么 UIViewController 在旋转时不填充窗口,而 UINavigationController 却填充窗口?

ios - 我在解析数据方面有问题?

ios - 如何获取 NSManagedObjectId 并检索数据

ios - 在调用 ParentViewController 的委托(delegate)方法之前将消息从 ChildViewController 传递到 ParentViewController

iphone - UIActivityIndi​​catorView 不消失