2013-03-20 54 views
0

在我的代碼中,我使用了一個tableview,其中一些方法被調用,而另一些則不是。表視圖委託方法不是所有調用

在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); 

} 
+0

是肯定的,你有UITableView鉤表? – 2013-03-20 12:24:00

+0

從你寫的東西看來,問題出在UITableViewDelegate上。你確定你正在執行協議嗎? – Petar 2013-03-20 12:26:31

+0

在.h文件中添加這一個UITableViewDelegate – Balu 2013-03-20 12:26:55

回答

0

問題不在於實現,而在於我的手勢識別。

我在我的視圖中添加了一個列表器,以便在我的文本框之外捕獲點擊事件,該事件被稱爲。我不完全知道爲什麼這兩個會發生衝突,但是當我將它刪除時,它正在工作。

tableview用於在我的文本框中自動完成。

-1

你這樣做:

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

在創建的tableView。

如果它是.xib文件,是否連接了委託和數據源?