【问题标题】:Activate UISearchDisplayController from another ViewController从另一个 ViewController 激活 UISearchDisplayController
【发布时间】:2015-01-26 22:54:50
【问题描述】:

我有一个应用程序可以从主屏幕上的搜索功能中受益。我已经编写了一些代码可以完成这项任务,但是它找不到结果,并且在点击 UISearchBar 上的 (x) 时崩溃。我一直在绞尽脑汁想弄清楚为什么它不起作用。

主视图控制器(主屏幕上有“搜索”栏):

 ViewController *viewController = [self.storyboard instantiateViewControllerWithIdentifier:@"CenterViewController"];


        [self.navigationController pushViewController:viewController animated:YES];
         [viewController sendSearchRequest:[nameLabel text] sport:[sportLabel text]];

ViewController(使用 tableview 和 UISearchDisplayController 查看)

-(void)sendSearchRequest:(NSString *)request sport:(NSString *)sport{
    [self.filteredArray removeAllObjects]; // First clear the filtered array.
    self.searchText = request;

    /*
     * Search the main list for products whose type matches the scope (if
     * selected) and whose name matches searchText; add items that match to the
     * filtered array.
     */
    [self.filteredArray removeAllObjects]; // First clear the filtered array.
    self.searchText = request;

    /*
     * Search the main list for products whose type matches the scope (if
     * selected) and whose name matches searchText; add items that match to the
     * filtered array.
     */
    NSLog(@"Request: %@", request);
    for (Athlete *athlete in self.athletes) {
        NSComparisonResult result = [[athlete name] compare:request options:(NSCaseInsensitiveSearch|NSDiacriticInsensitiveSearch) range:NSMakeRange(0, [request length])];
        if (result == NSOrderedSame) {
            [self.filteredArray addObject:athlete];
        }
    }
    [self.searchDisplayController setActive: YES animated: YES];
    [self.searchDisplayController.searchBar setText:request];



}

【问题讨论】:

    标签: ios cocoa-touch uisearchbar uisearchdisplaycontroller


    【解决方案1】:

    事实证明,这与正确激活无关。基本上,我有一个要过滤的数组,但它是在加载视图时初始化的。好吧,由于我将视图称为非常循环,因此它从未下载过数组。相反,我从主视图控制器下载了数组,并在搜索视图控制器中进行了搜索。问题解决了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-08-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-16
      • 1970-01-01
      • 1970-01-01
      • 2012-05-10
      相关资源
      最近更新 更多