2010-10-22 67 views
0

我有一個searchBar(with scopeBar),我想在服務器返回相關結果時關閉鍵盤。我有以下代碼:uiscrollview scrollViewWillBeginDragging messes up uitableview自定義單元格高度

- (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被稱爲 - 10X是準確的。

滾動表格會關閉鍵盤,但我注意到高度都是混亂的。在調試器中,我注意到,

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

使用比在每次heightForRowAtIndexPath使用一個不同的新小區。

這是錯誤?

我注意到,如果我不打電話給scrollViewWillBeginDragging方法,即使在重新加載表格後,uitableviewcell的高度都很好。

Thx提前。

回答

0

沒關係。我意識到表格叫做searchBarTextDidEndEditing,於是我在那裏做了一些額外的事情。

相關問題