2012-01-02 5 views
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"); 
} 

Нужно ли мне что-либо настройки на мой взгляд, сделал нагрузки, чтобы вызвать uitable метод делегата?

Обратите внимание, что я уже объявил UISearchDisplayDelegate, в моих .h файлах UISearchBarDelegate, UITableViewDataSource, UITableViewDelegate. Также работает мой метод tableView cellForRowAtIndexPath.

ответ

2

Вы на самом деле установить

self.tableView.delegate = self 

или соединив его в Interface Builder

+0

это право, а также убедитесь, что вы ставите '' в вашем файле .h – iNoob

+1

Спасибо ! Но где было бы лучше всего установить делегата? В режиме просмотра загрузился? В моем случае это будет self.resultTableView.delegate = self – Zhen

Смежные вопросы