Adding UISegmentedControl in UISearchDisplayController

点点圈 提交于 2019-12-23 02:38:39

问题


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


回答1:


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

Delegate method to handle scope button action

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


}



回答2:


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];



回答3:


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.



来源:https://stackoverflow.com/questions/30994608/adding-uisegmentedcontrol-in-uisearchdisplaycontroller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!