首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在UISearchDisplayController中添加UISegmentedControl

在UISearchDisplayController中添加UISegmentedControl
EN

Stack Overflow用户
提问于 2015-06-23 13:35:10
回答 3查看 1.3K关注 0票数 1

我想在searchBar下面和UISearchDisplayController的TableView之上添加UISegmentedControl。目前,UISearchDisplayController仅在其SearchBar下显示其tableView

但是我想在SearchBar下面添加一个UISegmentedControl,以便在顶部有SearchBar,在SearchBar之后有UISegmentedControl,在UISegmentedControl下面有UITableView。有没有办法使用UISearchDisplayController实现这一点,或者我必须制作自己SearchDisplayController,它有自己的SearchBarUISegmentedControlTableView

有什么建议吗?谢谢

EN

回答 3

Stack Overflow用户

发布于 2015-06-23 14:15:04

通过添加作用域标题启用ShowScopeBar并添加尽可能多的片段,并通过以下方法进行处理

由代码生成的

代码语言:javascript
复制
UISearchBar *searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
    [searchBar setShowsScopeBar:YES];
    [searchBar setScopeButtonTitles:@[@"button1",@"button2"]];
    [[self view] addSubview:searchBar];

由XIB开发的

处理范围按钮操作委托方法

代码语言:javascript
复制
- (void)searchBar:(UISearchBar *)searchBar selectedScopeButtonIndexDidChange:(NSInteger)selectedScope{


}
票数 4
EN

Stack Overflow用户

发布于 2015-06-23 13:43:53

在表中创建视图

代码语言:javascript
复制
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";

在该视图中添加搜索栏视图。

代码语言:javascript
复制
    [viewsearch addSubview:searchBar];

    searchBar.autoresizingMask = UIViewAutoresizingFlexibleWidth;

在此搜索视图中使用UISegmentedControl。

代码语言:javascript
复制
    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
EN

Stack Overflow用户

发布于 2015-06-23 16:56:25

我找到了我的问题的解决方案,我添加了UISegmentedControl作为UISearchDisplayController的TableView的头部。这样看起来就像我在UISearchDisplayController的searchBar下单独添加了一个UISegmentedControl。

感谢每一个想要帮助我的人。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30994608

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档