【问题标题】:Adding UISegmentedControl in UISearchDisplayController在 UISearchDisplayController 中添加 UISegmentedControl
【发布时间】:2015-09-08 18:28:29
【问题描述】:

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

但我想在SearchBar 下方添加一个UISegmentedControl,以便顶部有SearchBar,在SearchBar 之后我有一个UISegmentedControl,在UISegmentedControl 下方我有UITableView。这是使用UISearchDisplayController 的任何方法吗?还是我必须自己制作SearchDisplayController 并拥有自己的SearchBarUISegmentedControlTableView

有什么建议吗?谢谢

【问题讨论】:

    标签: ios uitableview uisearchbar uisegmentedcontrol uisearchdisplaycontroller


    【解决方案1】:

    启用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{
    
    
    }
    

    【讨论】:

      【解决方案2】:

      我找到了我的问题的解决方案,我将 UISegmentedControl 添加为 UISearchDisplayController 的 TableView 的标题。这样看起来就像我在 UISearchDisplayController 的 searchBar 下分别添加了一个 UISegmentedControl。

      感谢每一位试图提供帮助的人。

      【讨论】:

        【解决方案3】:

        在表格中创建视图

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

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2015-08-10
          • 2012-07-06
          • 1970-01-01
          • 2011-11-01
          • 2018-07-26
          • 2014-01-18
          • 1970-01-01
          • 2015-12-31
          相关资源
          最近更新 更多