1
嗨我正在使用searchDisplayController
篩選我的搜索結果。我的代碼片段如下:無法觸發UITableView委託方法「DidSelectRowAtIndexPath」
- (void)viewDidLoad
{
[super viewDidLoad];
//Set up search bar
UISearchBar *tempBar = [[UISearchBar alloc]initWithFrame:CGRectMake(0,0,320,40)];
self.sBar = tempBar;
[tempBar release];
self.sBar.delegate = self;
self.sBar.tintColor = [UIColor colorWithHexString:@"#b6c0c7"];
self.sBar.placeholder = @"Search Questions and Topics";
[self.view addSubview:sBar];
self.filteredListContent = [NSMutableArray arrayWithCapacity:[self.listContent count]];
self.searchDisplayController = [[UISearchDisplayController alloc] initWithSearchBar:sBar contentsController:self];
[self setSearchDisplayController:searchDisplayController];
[searchDisplayController setDelegate:self];
[searchDisplayController setSearchResultsDataSource:self];
// restore search settings if they were saved in didReceiveMemoryWarning.
if (self.savedSearchTerm)
{
[self.searchDisplayController setActive:self.searchWasActive];
[self.searchDisplayController.searchBar setText:savedSearchTerm];
self.savedSearchTerm = nil;
}
[self.resultTableView reloadData];
self.resultTableView.scrollEnabled = YES;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"zzz");
}
我是否需要在我的視圖中設置任何操作來觸發可用的委託方法?
請注意,我已經在我的.h文件中聲明瞭UISearchDisplayDelegate
,UISearchBarDelegate
,UITableViewDataSource
,UITableViewDelegate
。我的tableView cellForRowAtIndexPath
方法也在工作。
這是正確的,並且確保你把''在.h文件中 –
iNoob
2012-01-02 10:16:57
謝謝!但是,在哪裏設置代表的最佳位置?在視圖中加載?在我的情況下,它會是self.resultTableView.delegate = self – Zhen 2012-01-03 03:12:54