0

私はsearchBardisplayControllerを使用してテーブルビューに取り組んでいますが、検索を入力すると正しい結果が表示されますが、セルを選択すると別の選択が表示されます(テーブルビューが通常のときにセルを選択した場合、通常のインデックスパス)

だから、私のコードは次のとおりです。

行の数

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    // NSLog(@"%i", [[InfoWebDoctores sharedInstance]numberOfInfo]);

    if (tableView == self.searchDisplayController.searchResultsTableView) {
        return [displayObject count];
    } else  {
        return [allObject count];
    }

}

セルを構成します。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"docCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if(!cell)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"docCell"];
    }



    return cell;
}

検索を行います:

- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString
{
    if([searchString length] == 0)
    {
        [displayObject removeAllObjects];
        [displayObject addObjectsFromArray:allObject];
    }
    else
    {
        [displayObject removeAllObjects];
        for(NSDictionary *tmpDict in allObject)
        {
            NSString *val = [tmpDict objectForKey:doctorname];
            NSRange r = [val rangeOfString:searchString options:NSCaseInsensitiveSearch];

            NSString *val2 = [tmpDict objectForKey:doctoresp];
            NSRange r2 = [val2 rangeOfString:searchString options:NSCaseInsensitiveSearch];


            if(r2.location != NSNotFound || r.location != NSNotFound)
            {
                [displayObject addObject:tmpDict];
            }
        }
    }
    return YES;
}

そして最後にデータをdetailViewcontrollerに送信します(プッシュ接続を試しましたが、検索結果セルを選択してもプッシュビューを取得できません...)

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

    DetailTableViewController *detail = [self.storyboard instantiateViewControllerWithIdentifier:@"detailController"];


    NSIndexPath *index = [self.searchDisplayController.searchResultsTableView indexPathForSelectedRow];
    //NSIndexPath *index = [self.tableView indexPathForSelectedRow];
    int row = [index row];

    EntryJsonDoctores *entry = [[InfoWebDoctores sharedInstance]entryAtIndex:row];

    detail.modal = @[entry.nombre,entry.especialidad, entry.especialidad2, entry.especialidad3, entry.cel, entry.mail, entry.tel1, entry.tel2, entry.ext,entry.hospital,entry.direccion];


    [self presentViewController:detail animated:YES completion:^{

    }];
}

テーブルビューから選択した行のインデックスパスと検索結果コントローラーからのインデックスパスを試してみましたが、何が問題なのですか? 誰か助けてください

4

1 に答える 1

0

検索ディスプレイ コントローラーの resultsTableView のデリゲートをこのビュー コントローラーに設定すると、結果の TableView は didSelectRowAtIndexPath を探します。

これはviewDidLoadで行うことができますself.searchDisplayController.searchResultsTableView.delegate = self

NSIndexPath *index = [self.searchDisplayController.searchResultsTableView indexPathForSelectedRow];と 置き換えますNSIndexPath *index = indexPath;

于 2014-08-03T15:07:42.443 に答える