Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/102.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 搜索控制器问题_Ios_Objective C_Search - Fatal编程技术网

Ios 搜索控制器问题

Ios 搜索控制器问题,ios,objective-c,search,Ios,Objective C,Search,我有一个问题,我正试图让我的搜索栏工作,但它在这里停止这一点基本上导致应用程序崩溃。我愿意接受任何关于如何更好地添加搜索栏的建议。对我能做什么有什么建议吗?感谢您的帮助 如果要在主线程中更新数据 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath** { static NSString *CellIdentifier = @"Tabl

我有一个问题,我正试图让我的搜索栏工作,但它在这里停止这一点基本上导致应用程序崩溃。我愿意接受任何关于如何更好地添加搜索栏的建议。对我能做什么有什么建议吗?感谢您的帮助

如果要在主线程中更新数据

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath**
{

    static NSString *CellIdentifier = @"TableCell";
    TableCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];**

    // Configure the cell...

    int row = [indexPath row];

    cell.TitleLabel.text = _Title[row];
    cell.DescriptionLabel.text = _Description[row];
    cell.FeeSchedule.text = _Fschedule[row];
    cell.NonFS.text = _Nonfeeschedule[row];
    cell.ThumbImage.image = [UIImage imageNamed:_Images[row]];

    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }

    cell.textLabel.text = [medicalCodes objectAtIndex:indexPath.row];
    return cell;


    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }

    if (tableView == self.searchDisplayController.searchResultsTableView) {
        cell.textLabel.text = [searchResults objectAtIndex:indexPath.row];
    } else {
        cell.textLabel.text = [medicalCodes objectAtIndex:indexPath.row];
    }

    return cell;
}


-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {


    if([[segue identifier] isEqualToString:@"ShowDetails"]) {
        DetailViewController *detailviewcontroller = [segue destinationViewController];

        NSIndexPath *myIndexPath = [self.tableView indexPathForSelectedRow];

        int row = [myIndexPath row];
        detailviewcontroller.DetailModal = @[_Title[row],_Description[row],_Fschedule[row],_Nonfeeschedule[row],_Images[row]];
    }
}

`enter code here`- (void)filterContentForSearchText:(NSString*)searchText scope:(NSString*)scope
{
    NSPredicate *resultPredicate = [NSPredicate
                                    predicateWithFormat:@"SELF contains[cd] %@",
                                    searchText];

    searchResults = [medicalCodes filteredArrayUsingPredicate:resultPredicate];
}

-(BOOL)searchDisplayController:(UISearchDisplayController *)controller
shouldReloadTableForSearchString:(NSString *)searchString
{
    [self filterContentForSearchText:searchString
                               scope:[[self.searchDisplayController.searchBar scopeButtonTitles]
                                      objectAtIndex:[self.searchDisplayController.searchBar
                                                     selectedScopeButtonIndex]]];

    return YES;
}

如果要使用UI主线程重新加载tableview更新

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath**
{

    static NSString *CellIdentifier = @"TableCell";
    TableCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];**

    // Configure the cell...

    int row = [indexPath row];

    cell.TitleLabel.text = _Title[row];
    cell.DescriptionLabel.text = _Description[row];
    cell.FeeSchedule.text = _Fschedule[row];
    cell.NonFS.text = _Nonfeeschedule[row];
    cell.ThumbImage.image = [UIImage imageNamed:_Images[row]];

    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }

    cell.textLabel.text = [medicalCodes objectAtIndex:indexPath.row];
    return cell;


    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }

    if (tableView == self.searchDisplayController.searchResultsTableView) {
        cell.textLabel.text = [searchResults objectAtIndex:indexPath.row];
    } else {
        cell.textLabel.text = [medicalCodes objectAtIndex:indexPath.row];
    }

    return cell;
}


-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {


    if([[segue identifier] isEqualToString:@"ShowDetails"]) {
        DetailViewController *detailviewcontroller = [segue destinationViewController];

        NSIndexPath *myIndexPath = [self.tableView indexPathForSelectedRow];

        int row = [myIndexPath row];
        detailviewcontroller.DetailModal = @[_Title[row],_Description[row],_Fschedule[row],_Nonfeeschedule[row],_Images[row]];
    }
}

`enter code here`- (void)filterContentForSearchText:(NSString*)searchText scope:(NSString*)scope
{
    NSPredicate *resultPredicate = [NSPredicate
                                    predicateWithFormat:@"SELF contains[cd] %@",
                                    searchText];

    searchResults = [medicalCodes filteredArrayUsingPredicate:resultPredicate];
}

-(BOOL)searchDisplayController:(UISearchDisplayController *)controller
shouldReloadTableForSearchString:(NSString *)searchString
{
    [self filterContentForSearchText:searchString
                               scope:[[self.searchDisplayController.searchBar scopeButtonTitles]
                                      objectAtIndex:[self.searchDisplayController.searchBar
                                                     selectedScopeButtonIndex]]];

    return YES;
}

在这里查看您的代码,您甚至在分配单元之前就已经配置了单元。 而你在下一行之后所写的代码将在你回电话后保持不变

             dispatch_async(dispatch_get_main_queue(), ^(void){
              [self.tableView reloadData]
             });
我不确定您在-tableView:cellforrowatinexpath:中试图实现什么。但我建议你试试这个

cell.textLabel.text = [medicalCodes objectAtIndex:indexPath.row];
  return cell;

您应该更新主线程中的数据,请提供崩溃日志在您重新加载tableview的任何地方***第一次抛出调用堆栈:0x30c10f03 0x3b57fce7 0x30b47331 0x2973d5 0x336f9e01 0x336a115b 0x336a09b1 0x335c7185 0x3324312b 0x3323e94f 0x3326d95d 0x33643617 0x33641c21 0x33640e5f 0x33640de7 0x33640d7f 0x33639481 0x335cd50f 0x33640ad1 0x336405a50x335d2485 0x335cfc49 0x33639851 0x336364f5 0x33630ad9 0x335ccb0f 0x335CB71 0x3363015 0x35c80b55 0x35c8073f 0x30bdb83f 0x30bdb7db 0x30bd9fa7 0x30b447a9 0x30b4458b 0x3362f43b 0x3362a6d9 0x298379 0xBA99AB7 libc++abi.dylib:终止时出现NSException lldbWell类型的未捕获异常,由于许多原因,该错误将向您抛出。我建议您检查调用堆栈!在Xcode中设置所有异常断点按导航器中断点窗格底部的+按钮。然后,当异常发生时,您将进入调试器。您可以使用bt命令记录回溯。当然,您可以在调试导航器中找到此跟踪。