Adding UISegmentedControl in UISearchDisplayController

1.3k views Asked by At

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

But i want to add a UISegmentedControl below the SearchBar so that I have SearchBar on the top, after SearchBar I have a UISegmentedControl and below that UISegmentedControl I have UITableView. Is that any way to do this using UISearchDisplayController or i have to make my own SearchDisplayController that have its own SearchBar , UISegmentedControl and TableView?

any suggestion? Thanks

3

There are 3 answers

0
Abuzar Amin On

I find the solution for my Problem that i added the UISegmentedControl as a Header of TableView of UISearchDisplayController. In this way it just looked like that i have added a UISegmentedControl Separately under the searchBar of UISearchDisplayController.

Thank You every one who tried to help.

0
AudioBubble On

Create a view in 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 e.g. jacket";

Addsearchbar view in that view.

    [viewsearch addSubview:searchBar];

    searchBar.autoresizingMask = UIViewAutoresizingFlexibleWidth;

Use UISegmentedControl in this searchview.

    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];
0
abhishekkharwar On

Enable ShowScopeBar and add as many as segments by adding scop titles and handle them by following method

By Code

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

By XIB

enter image description here

Delegate method to handle scope button action

- (void)searchBar:(UISearchBar *)searchBar selectedScopeButtonIndexDidChange:(NSInteger)selectedScope{


}