1

嗨,我正在使用 asearchDisplayController来过滤我的搜索结果。我的代码片段如下:

- (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方法也有效。

4

1 回答 1

3

你真的设置

self.tableView.delegate = self

或在 Interface Builder 中连接它

于 2012-01-02T02:45:39.323 回答