我想在searchBar下面和UISearchDisplayController的TableView之上添加UISegmentedControl。目前,UISearchDisplayController仅在其SearchBar下显示其tableView。
但是我想在SearchBar下面添加一个UISegmentedControl,以便在顶部有SearchBar,在SearchBar之后有UISegmentedControl,在UISegmentedControl下面有UITableView。有没有办法使用UISearchDisplayController实现这一点,或者我必须制作自己SearchDisplayController,它有自己的SearchBar、UISegmentedControl和TableView
有什么建议吗?谢谢
发布于 2015-06-23 14:15:04
通过添加作用域标题启用ShowScopeBar并添加尽可能多的片段,并通过以下方法进行处理
由代码生成的
UISearchBar *searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
[searchBar setShowsScopeBar:YES];
[searchBar setScopeButtonTitles:@[@"button1",@"button2"]];
[[self view] addSubview:searchBar];由XIB开发的

处理范围按钮操作的委托方法
- (void)searchBar:(UISearchBar *)searchBar selectedScopeButtonIndexDidChange:(NSInteger)selectedScope{
}发布于 2015-06-23 13:43:53
在表中创建视图
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";在该视图中添加搜索栏视图。
[viewsearch addSubview:searchBar];
searchBar.autoresizingMask = UIViewAutoresizingFlexibleWidth;在此搜索视图中使用UISegmentedControl。
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];发布于 2015-06-23 16:56:25
我找到了我的问题的解决方案,我添加了UISegmentedControl作为UISearchDisplayController的TableView的头部。这样看起来就像我在UISearchDisplayController的searchBar下单独添加了一个UISegmentedControl。
感谢每一个想要帮助我的人。
https://stackoverflow.com/questions/30994608
复制相似问题