Adding a UISegmentedControl to a UISearchDisplayController

I want to add a UISegmentedControl below the searchBar and above the TableView of the UISearchDisplayController . Currently, the UISearchDisplayController only shows a tableView under its searchBar .

But I want to add a UISegmentedControl below the searchBar , so that I have a searchBar on top, after the searchBar I have a UISegmentedControl , and below the UISegmentedControl I have a UITableView . Is this any way to do this using the UISearchDisplayController , or should I create my own SearchDisplayController that has its own searchBar , UISegmentedControl and tableView ?

any suggestion? thanks

+1
source share
3 answers

Turn on ShowScopeBar and add as many segments by adding parenthesis headers and processing them following the method

By code

 UISearchBar *searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)]; [searchBar setShowsScopeBar:YES]; [searchBar setScopeButtonTitles:@[@"button1",@"button2"]]; [[self view] addSubview:searchBar]; 

XIB

enter image description here

Delegation method for controlling actions using a button

 - (void)searchBar:(UISearchBar *)searchBar selectedScopeButtonIndexDidChange:(NSInteger)selectedScope{ } 
+3
source

Create a view in a table

 UIView *viewsearch=[[UIView alloc]initWithFrame:CGRectMake(0,-10, 320,83)]; [self.tblname addSubview:viewsearch]; [self.view addGestureRecognizer:revealController.panGestureRecognizer] UISearchBar *searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0,5, 320, 40)]; searchBar.autoresizingMask = UIViewAutoresizingFlexibleWidth; searchBar.delegate=self; [searchBar setBarTintColor:[UIColor colorWithRed:(249/255.0) green:(9/255.0) blue:(99/255.0) alpha:1]]; searchBar.tintColor = [UIColor whiteColor]; searchBar.placeholder = @"Search items eg jacket"; 

Add a view to the search bar in this view.

  [viewsearch addSubview:searchBar]; searchBar.autoresizingMask = UIViewAutoresizingFlexibleWidth; 

Use the UISegmentedControl in this search.

  NSArray *itemArray = [NSArray arrayWithObjects: @"General", @"Near me", nil]; UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:itemArray]; segmentedControl.frame = CGRectMake(50,53, 225, 22); segmentedControl.segmentedControlStyle = UISegmentedControlStylePlain; [segmentedControl addTarget:self action:@selector(MySegmentControlAction:) forControlEvents: UIControlEventValueChanged]; segmentedControl.selectedSegmentIndex = 0; segmentedControl.tintColor = [UIColor colorWithRed:(249/255.0) green:(10/255.0) blue:(99/255.0) alpha:1]; segmentedControl.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleBottomMargin; [viewsearch addSubview:segmentedControl]; 
+1
source

I found a solution to my problem that I added the UISegmentedControl as the TableView header for the UISearchDisplayController. So it was like I added the UISegmentedControl separately under the searchBar of the UISearchDisplayController.

Thanks to everyone who tried to help.

0
source

All Articles