I have a searchBar (with scopeBar) where I want to dismiss the keyboard when the server returns relevant results. I have the following code:
- (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;
}
and
- (void)searchBarTextDidBeginEditin开发者_运维问答g:(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;
}
When the server returns the data, I call
[homeTable reloadData];
whereupon my - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
is called - 10x to be exact.
Scrolling the table will dismiss the keyboard, but I notice that the heights are all messed up. In the debugger, I noticed that
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
uses a fresh cell different than the one used in heightForRowAtIndexPath
every time.
Is this an error?
I notice that if I don't call the scrollViewWillBeginDragging
method, the uitableviewcell heights are all fine, even after reloading the table.
Thx in advance.
nevermind. I realized that the table calls searchBarTextDidEndEditing
, whereupon i was doing some extra things in there.
精彩评论