gpt4 book ai didi

objective-c - 无法触发 UITableView 委托(delegate)方法 "DidSelectRowAtIndexPath"

转载 作者:行者123 更新时间:2023-12-01 19:24:17 26 4
gpt4 key购买 nike

嗨,我正在使用 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");
}

我是否需要在我的 View 中设置任何加载来触发合适的委托(delegate)方法?

请注意,我已经声明了 UISearchDisplayDelegate , UISearchBarDelegate , UITableViewDataSource , UITableViewDelegate在我的 .h 文件中。还有我的 tableView cellForRowAtIndexPath方法有效。

最佳答案

你真的设置

self.tableView.delegate = self

或在 Interface Builder 中连接它

关于objective-c - 无法触发 UITableView 委托(delegate)方法 "DidSelectRowAtIndexPath",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8696986/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com