无法触发UITableView委托方法“DidSelectRowAtIndexPath”

时间:2012-01-02 02:34:21

标签: objective-c ios didselectrowatindexpath uitableview

您好我使用searchDisplayController来过滤搜索结果。我的代码段如下:

- (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委托方法?

请注意,我已在我的.h文件中声明了UISearchDisplayDelegateUISearchBarDelegateUITableViewDataSourceUITableViewDelegate。我的tableView cellForRowAtIndexPath方法也正常运作。

1 个答案:

答案 0 :(得分:3)

你真的设置了

self.tableView.delegate = self

或在Interface Builder中连接它