Header view is not display after search iOS8 + XCo

2019-06-22 07:28发布

问题:

I have working application for iOS7 and below
I used UISearchDisplayController for search in table.

Problem :
After search header view is not display in iOS8.
as display in below images.

Before search :

After search :


I tried using UISearchController but also have same problem i used this code link

I add below code in TPSMastreViewController.m

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


I checked that delegate - (UIView *)tableView:(UITableView *)tableView
viewForHeaderInSection:(NSInteger)section
is not called in the case of iOS8.
Edit :
What i understand is only UITableViewDataSource delegate is called, UITableViewDelegate did not.
Please not that i set both delegate in ViewDidLoad
Question :
1] Is it an UI change ?
2] Any one have patch so that delegate method will call forcefully.

回答1:

I found answer so writing here it may help others facing same problem

just need to add delegate heightForHeaderInSection and it will show header view for both searchResultsController for UISearchController(iOS8) and searchResultsTableView for UISearchDisplayController(iOS7)

Add below code in TPSMastreViewController.m and it will solve problem.

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

I found my answer by reading this question :)
in iOS 8 UITableView heightForHeaderInSection is not optional