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

发布于 2024-12-23 17:16:17 字数 1654 浏览 1 评论 0原文

您好,我正在使用 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 方法也正在工作。

Hi I am using a searchDisplayController to filter through my search results. My code snippet is as follows:

- (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");
}

Do I need to setup anything in my view did load to trigger the uitable delegate method?

Note that I have already declared UISearchDisplayDelegate, UISearchBarDelegate, UITableViewDataSource, UITableViewDelegate in my .h files. Also my tableView cellForRowAtIndexPath method is working.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

请帮我爱他 2024-12-30 17:16:17

您是否

self.tableView.delegate = self

已在 Interface Builder 中实际设置或连接它

Have you actually set

self.tableView.delegate = self

or connected it up in Interface Builder

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文