5

我有適用於iOS7和以下版本的工作應用程序
我在表中使用UISearchDisplayController進行搜索。
搜索後不顯示標題視圖iOS8 + XCode6

問題:
後搜索標題視圖中未顯示iOS8上。
顯示在下圖中。

之前搜索: enter image description here

搜索後: enter image description here


我嘗試使用UISearchController也有同樣的問題 我用這個代碼 link

我添加下面的代碼在T中PSMastreViewController.m

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section 
{ 
    UIView *v = [[UIView alloc] init]; 
    v.backgroundColor = [UIColor greenColor]; 
    return v; 
} 


我檢查了委託 - (UIView的*)的tableView:(UITableView的*)的tableView
viewForHeaderInSection:(NSInteger的)部分
沒有在iOS8上的情況下調用。
編輯:
我的理解是隻有UITableViewDataSource委託被調用,UITableViewDelegate沒有。
請不是我在viewDidLoad中同時設置委託
問:
1]它是一個UI的變化?
2]任何人都有補丁,以便委託方法將強制調用。

回答

5

我找到答案這麼寫,這可以幫助其他面臨同樣問題

只需要添加委託heightForHeaderInSection,它會顯示兩個searchResultsController爲UISearchController程序(iOS 8)和searchResultsTableView爲UISearchDisplayController頭視圖(iOS7 )

在TPSMastreViewController.m中添加以下代碼,它將解決問題。

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section 
{ 
    return 20; 
} 

我通過閱讀這個問題:)
in iOS 8 UITableView heightForHeaderInSection is not optional

+0

如果你的頭的高度總是20,然後,而不是僅僅實現設定的UITableView的sectionHeaderHeight財產委託方法找到我的答案。如果您有1000個分區,那麼表格將高度乘以1000以獲得總高度的速度要快於調用委託方法1000次。 – SomeGuy 2014-09-21 05:56:18

+0

感謝您的建議,但我的問題是委託方法viewForHeaderInSection哪裏沒有調用,搜索後,實現了這個viewForHeaderInSection後,其調用。 – Jageen 2014-09-21 07:50:37

+0

試試這個,它也會工作(並且表現更好)[self。tableView setSectionHeaderHeight:20]; – SomeGuy 2014-09-21 09:38:02

相關問題