0

私のコードでは、一部のメソッドが呼び出されているテーブルビューを使用していますが、他のメソッドは呼び出されていません。

initwithframe:

_table.delegate = self;
_table.dataSource = self;

これは呼ばれます

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *identifier = @"TRAutocompleteCell";

    id cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (cell == nil)
        cell = [_cellFactory createReusableCellWithIdentifier:identifier];

    NSLog(@"got here 3");

    NSAssert([cell isKindOfClass:[UITableViewCell class]], @"Cell must inherit from UITableViewCell");
    NSAssert([cell conformsToProtocol:@protocol(TRAutocompletionCell)], @"Cell must conform TRAutocompletionCell");
    UITableViewCell <TRAutocompletionCell> *completionCell = (UITableViewCell <TRAutocompletionCell> *) cell;

    id suggestion = self.suggestions[(NSUInteger) indexPath.row];
    NSAssert([suggestion conformsToProtocol:@protocol(TRSuggestionItem)], @"Suggestion item must conform TRSuggestionItem");
    id <TRSuggestionItem> suggestionItem = (id <TRSuggestionItem>) suggestion;

    [completionCell updateWith:suggestionItem];

    return cell;
}

しかし、これは同じファイルで呼び出されていません。

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    NSLog(@"got here 5");
    id suggestion = self.suggestions[(NSUInteger) indexPath.row];
    NSLog(@"got here 4");
    NSAssert([suggestion conformsToProtocol:@protocol(TRSuggestionItem)], @"Suggestion item must conform TRSuggestionItem");

    self.selectedSuggestion = (id <TRSuggestionItem>) suggestion;

    _queryTextField.text = self.selectedSuggestion.completionText;
    [_queryTextField resignFirstResponder];

    if (self.didAutocompleteWith)
        self.didAutocompleteWith(self.selectedSuggestion);

}
4

2 に答える 2

0

問題は実装ではなく、私のジェスチャー認識にありました。

ビューにリスターを追加して、呼び出されていたテキスト ボックスの外側のタップ イベントをキャッチしました。この 2 つが衝突している理由は正確にはわかりませんが、削除すると機能していました。

テーブルビューは、テキスト ボックスのオートコンプリート用です。

于 2013-03-20T12:45:42.843 に答える
-1

しましたか:

yourTableView.delegate = self;
yourTableView.dataSource = self;

tableViewの作成中。

.xib ファイルの場合、delegate と dataSource を接続しましたか?

于 2013-03-20T12:47:40.563 に答える