单击UISearchBar的取消按钮后,如何使用UISearchBar刷新UITableView? [英] How to refresh my UITableView with UISearchBar after click of cancel button of UISearchBar?

查看:58
本文介绍了单击UISearchBar的取消按钮后,如何使用UISearchBar刷新UITableView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将UITableView与UIViewBar放在表视图的顶部,对我来说一切正常,除了一个问题,例如,如果我搜索一个字母,则uitableview中的搜索结果将被过滤,此后它很好,如果我将搜索结果滚动到表视图的末尾,则如果按uisearchbar的取消"按钮,表视图将刷新所有数据,但不是从第一个单元格显示,而是从(大约第25个单元格)显示,就像我滚动了多少一样在我的搜索结果中,单击取消"后显示的内容有很多长度.我也不知道我在调用重载数据是什么问题,我需要在开始加载时显示tableview.

I'm using a UITableView with an UISearchBar on top of table view, for me every thing is working fine except only one problem like if i search for a letter the search results in uitableview is getting filtered and its fine after that , if i scroll the search result till end of my tableview then if i press cancel button of my uisearchbar the tableview is refreshing all data but it is displaying not from the first cell, it is displaying from (approx 25th cell) like how much i scroll in my search result that much length after it is displaying after click of cancel.I don't know what is the problem i'm calling reload data also , i need to display tableview as it loads in beginning.

需要任何帮助,谢谢.

推荐答案

在您的-(void)searchBarCancelButtonClicked:(UISearchBar *)searchBar 委托中处理取消"按钮的方法,您可以添加一些像这样滚动回到表格视图顶部的代码

In your - (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar Delegate method which handles the Cancel button you could add a bit of code to scroll back to the top of the Table View like so

- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar {
    // ... Code to refresh the Table View

    // Reload the Table View
    [self.tableView reloadData];

    // Scroll to top
    [self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:YES];
}

您可能需要在滚动位置上播放.代替 UITableViewScrollPositionTop ,您可能需要使用 UITableViewScrollPositionMiddle UITableViewScrollPositionBottom 甚至是 UITableViewScrollPositionNone

You may need to play with the scroll position. Instead of UITableViewScrollPositionTop you may need to use UITableViewScrollPositionMiddle or UITableViewScrollPositionBottom or even UITableViewScrollPositionNone

这篇关于单击UISearchBar的取消按钮后,如何使用UISearchBar刷新UITableView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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