0

UISearchDisplayController私はiphoneアプリケーションの画面の1つで使用しています.私の必要性はUISearchDisplayController、uisearchbarでユーザータイプとしてのみ表示することです.searchtableviewをロードしてデータを表示します.今、私の問題はすべてうまくいっていますが、行を選択しようとするとデリゲート-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPathが起動しないため、検索バーのキャンセルボタンをクリックするまで検索テーブルビューは非表示になりません。 -削除方法を選択します。

私は次のことをしました。誰でも私の間違いを教えてください。

注:画面に他のテーブルビューはありません。検索ディスプレイコントローラーのuisearchtableviewだけです(問題の原因ですか?)

self.searhController = [[UISearchDisplayController alloc]
                                            initWithSearchBar:self.searchBar
                                            contentsController:self];
    self.searhController.delegate=self;



    self.searhController.searchResultsDataSource = self;
    self.searhController.searchResultsDelegate = self;
    self.edgesForExtendedLayout = UIRectEdgeNone;

    [self.searhController setDelegate:self];
    [self.searhController setSearchResultsDelegate:self];
    [self.searhController setSearchResultsDelegate:self];

#pragma mark TableView Delegate

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    if (tableView== self.searhController.searchResultsTableView) {
        if(self.searchResults.count<=0)
            return 0;
        else
            return self.searchResults.count;
    }
    else{
        return 0;    }



}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *simpleTableIdentifier = @"SimpleTableItem";
    tableView.delegate=self;
    tableView.dataSource=self;
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
    if(tableView==self.searhController.searchResultsTableView){


        if (cell == nil) {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
        }
        City *cityObj=[self.searchResults objectAtIndex:indexPath.row];
        cell.textLabel.text = cityObj.name;
    }

    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{



    if (tableView==self.searhController.searchResultsTableView) {
        [self.searhController setActive:NO animated:YES];


        [self.searchDisplayController setActive:NO animated:YES];
        [self.searhController setActive:NO animated:NO];

    }

}
- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString{

    if ([[searchString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] length])
        self.tvSearchView = self.searhController.searchResultsTableView;
    else
        self.tvSearchView = controller.searchResultsTableView;


    if(searchString.length>=3){


        [self getCityList:searchString];

        return YES;

    }
    else{
    return NO;
    }

}
4

1 に答える 1

1

あなたのように、ビューにいくつかのtapGestureを設定したので、でビューにジェスチャーを追加しないでviewDidLoad()ください。テキストフィールドに入力を開始するときにジェスチャーをビューに追加し、didFinish入力するとビューからジェスチャーを削除します。didslect()したがって、問題からテーブルビューに影響を与えました

于 2014-08-07T12:01:03.067 に答える