4

我有一個RectEdgeAll視圖控制器的tableview並作爲其的tableview報頭中的搜索欄。當我開始搜索時,搜索欄開始動畫並定位到屏幕頂部的正常位置,但是tableview沒有跟隨它,它在開始搜索之前保持在同一位置,在兩個視圖之間留下間隙。我如何使它與搜索欄一起生成動畫?的iOS 7 searchdisplaycontroller和的tableview偏移不同意偏移

我已經嘗試過更新的tableview的contentOffset當搜索的開始,但它甚至沒有移動。

嘗試了兩種方式的tableview和搜索欄:代碼和故事板。

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    self.tableView.dataSource = self; 
    self.tableView.delegate = self; 

    //self.searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)]; 
    self.searchBar.delegate = self; 
    self.searchController = [[UISearchDisplayController alloc] initWithSearchBar:self.searchBar contentsController:self]; 
    self.searchController.delegate = self; 


} 

- (void)viewWillAppear:(BOOL)animated 
{ 
    [super viewWillAppear:animated]; 
    [self.view addSubview:self.tableView]; 
    self.tableView.tableHeaderView = self.searchBar; 
} 

之前搜索:

enter image description here

+0

查看此頁面http://myioscodingtips.blogspot.ca/2013/10/uisearchdisplaycontroller-in-ios6-ios7.html –

回答

0

我的問題通過增加

[self.view addSubview:self.tableView]; self.tableView.tableHeaderView = self.searchBar;

解決:

enter image description here

搜索後

這兩行中的viewDidLoad函數。 如果我使用

[self.tableView setFrame:CGRectMake(0, 0, 320, 400)]; 

設置表視圖的框架,並把在viewdidappear功能的線路和我目前的ViewController有navigationcontroller這個實現代碼如下那張navigationcontroller落後,但如果我把這些線在viewDidLoad中的tableview從剛開始在navigationcontroller下。不知道爲什麼會這樣