在我的代码中,我使用了一个 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);
}