5

我通常使用[self.tableView setContentOffset:CGPointMake(0,40)];來隱藏導航條下面的UISearchBar(我將它設置爲tableView的標題)。工作一切良好,在viewDidLoad中:搜索欄是的導航欄下方的視圖加載時。然後,我把代碼在cancelButton被調用後隱藏UISearchBar下面的UINavigationBar

[self.tableView setContentOffset:CGPointMake(0,40)] 

同一行中

- (void)searchDisplayControllerWillEndSearch:(UISearchDisplayController *)controller 

,但它沒有做任何事情:搜索欄仍然可見,當單擊取消按鈕。 有什麼問題?

回答

1

下面是從主線程被調用的方法?

- (void)searchDisplayControllerWillEndSearch:(UISearchDisplayController *)controller 

您可以檢查這樣的:

if ([NSThread isMainThread]) { 
    NSLog(@"Yes it is the main thread."); 
} 

否則,任何觀點的變化不會在屏幕上註冊。如果你必須從一個單獨的線程修改視圖您可以使用此:

[self performSelectorOnMainThread:@selector(XXX) withObject:nil waitUntilDone:NO]; 

我不知道如果這是你的問題,但它是在那裏我開始尋找。

4

下面的方法應該這樣做:

-(void)searchDisplayControllerDidEndSearch:(UISearchDisplayController *)controller{ 
    [self.tableView setContentOffset:CGPointMake(0,40)];  
} 
+0

確保您添加的UISearchBar的實現代碼如下。那麼只有contentOffset概念將正常工作。 – 2013-08-06 11:41:50

相關問題