我有一个searchBar(带有scopeBar),我想在服务器返回相关结果时关闭键盘。我有以下代码:
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
[search resignFirstResponder];
//height - navBar - searchBar - carrierBar - uitabbar
CGRect newFrame = CGRectMake(0, 44, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height-44-44-20-49);
homeTable.frame = newFrame;
}
和
- (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar {
//[self.navigationController setNavigationBarHidden:YES animated:YES];
searchBar.scopeButtonTitles = kScopeButtonTitles;
searchBar.showsScopeBar = YES;
[searchBar sizeToFit];
[searchBar setShowsCancelButton:YES animated:YES];
//resize the table for the scope bar
//uitabbar height is 49
//uinavigationbar is 44
//uisearchbar and scope is 44 each
//UIkeyboard is 216
//UITabBar is covered by UIKeyboard, so it doesn't have to be subtracted.
//carrier status bar is 20
CGRect newFrame = CGRectMake(0, 88, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height-44-88-216-20);
homeTable.frame = newFrame;
}
当服务器返回数据时,我调用
[homeTable reloadData];
于是我的- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
被称为 - 确切地说是10倍。
滚动表会关闭键盘,但我注意到高度都搞砸了。在调试器中,我注意到了
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
每次使用的新单元格与heightForRowAtIndexPath
中使用的单元格不同。
这是一个错误吗?
我注意到如果我不调用scrollViewWillBeginDragging
方法,即使重新加载表格之后,uitableviewcell的高度也很好。
答案 0 :(得分:0)
没关系。我意识到表调用searchBarTextDidEndEditing
,于是我在那里做了一些额外的事情。