How to hide section title if result is not found using search bar in ios8

IF Name is present then it will look like this

IF Name is not present then it look like this i want to hide section title if name is not present

-(NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView { if (_segment.selectedSegmentIndex==0) { return sortedKeys; } else { return sortedKeys1; } } 

I use this code, but I don’t need the section title, if the name is missing, now it gives me all the section titles

+5
source share
3 answers

If there are no lines, set the section title to nil.

 -(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { if ([tableView.dataSource tableView:tableView numberOfRowsInSection:section] == 0) { return nil; } else { return "section title \(section)" } return @""; } 

This will work.

+1
source

Try returning 0 to numberOfSectionsInTableView

 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { if (result_not_found) { /// pass the condition when "result not found" here return 0; } if (_segment.selectedSegmentIndex==0) { return ([sortedKeys count]); } else { return ([sortedKeys1 count]); } } 
+1
source

You should either use this by returning the correct number of partitions:

 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView; 

Or this returning CGFLOAT_MIN if there are no lines in the corresponding section:

 - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section; 

Hope this helps.

Tom

0
source

Source: https://habr.com/ru/post/1233683/


All Articles