gpt4 book ai didi

ios - UISearchBars。复制数组始终等于 Nil

转载 作者:行者123 更新时间:2023-11-29 03:27:03 24 4
gpt4 key购买 nike

 - (void)searchTableList {
NSString *searchString = searchBar.text;
NSString *str=[[stories valueForKeyPath:@"name"] componentsJoinedByString:@"@"];
NSLog(@"desired string:%@",str);
NSMutableArray *array = [[NSMutableArray alloc]init];
array = [str componentsSeparatedByString:@"@"];

//永远不要尝试与字典数组进行比较,必须先提取字符串

        for (NSString *tempStr in stories) {
NSComparisonResult result = [tempStr compare:searchString options:(NSCaseInsensitiveSearch|NSDiacriticInsensitiveSearch) range:NSMakeRange(0, [searchString length])];
if (result == NSOrderedSame) {
[filteredContentList addObject:tempStr];
}
}
}

最佳答案

首先,filteredContentList 从未在您上面的代码中分配,因此它将始终指向 nil。在 viewDidLoad 中添加 filteredContentList = [NSMutableArray array] 之类的东西。其次,您依靠 isSearching boolean 标志来检测您是在处理搜索结果 TableView 还是 Controller 的一般 TableView 。恕我直言,这是不好的做法。您应该依赖 tableView 参数,该参数被传递给 TableView 委托(delegate)的每个方法(在您的情况下——您的 UITableViewController)。设置标签或将 tableView 参数与 self.tableView 进行比较。最后一件事 -- 您不需要在 viewDidLoad 调用 reloadData

关于ios - UISearchBars。复制数组始终等于 Nil,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20325019/

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