簡體   English   中英

如何在單擊UISearchBar的取消按鈕后使用UISearchBar刷新我的UITableView?

[英]How to refresh my UITableView with UISearchBar after click of cancel button of UISearchBar?

我正在桌面視圖上使用帶有UISearchBar的UITableView,對我來說每件事情都工作得很好,除了一個問題,如果我搜索一個字母,uitableview中的搜索結果會被過濾,之后就好了,如果我滾動搜索結果直到我的tableview結束然后,如果我按下我的uisearchbar的取消按鈕,tableview刷新所有數據,但它不顯示從第一個單元格,它顯示從(約25個單元格)像我在搜索中滾動多少點擊取消后顯示的結果很長。我不知道我正在調用重載數據是什么問題,我需要在開始時加載顯示tableview。

提前感謝任何幫助。謝謝。

在你的- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar Delegate方法中處理Cancel按鈕你可以添加一些代碼來滾動回到Table View的頂部,就像這樣

- (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你可能需要使用UITableViewScrollPositionMiddleUITableViewScrollPositionBottom甚至UITableViewScrollPositionNone

在表視圖上調用以下方法:

[self.tableView reloadData];

然后它刷新你的表視圖

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM