我想在UISegmentedControl
下方添加searchBar
,并在UISearchDisplayController
的TableView上方添加UISearchDisplayController
。目前tableView
仅在其SearchBar
下显示其UISegmentedControl
。
但我想在SearchBar
下面添加SearchBar
,以便SearchBar
UISegmentedControl
之后UISegmentedControl
位于UITableView
之上UISearchDisplayController
我有SearchDisplayController
。这是使用SearchBar
执行此操作的任何方式吗?或者我必须创建自己的UISegmentedControl
TableView
,COUNT
和SELECT *
FROM (SELECT USER_ID,COUNT(comp_id) as numberr
FROM COMPETITION
GROUP BY USER_ID
ORDER BY COUNT(comp_id) DESC) T1
WHERE rownum=1;
?
有什么建议吗?谢谢
答案 0 :(得分:3)
启用ShowScopeBar
并通过添加scop标题添加尽可能多的段,并按照以下方法处理它们
按代码
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{
}
答案 1 :(得分:1)
在表格中创建视图
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];
答案 2 :(得分:0)
我找到了我的问题的解决方案,我添加了UISegmentedControl作为UISearchDisplayController的TableView的标头。这样看起来我只是在UISearchDisplayController的searchBar下单独添加了一个UISegmentedControl。
感谢每一位试图提供帮助的人。