gpt4 book ai didi

iphone - 返回结果时搜索显示 Controller 崩溃

转载 作者:行者123 更新时间:2023-12-03 17:43:48 24 4
gpt4 key购买 nike

我有一个带有搜索显示 Controller 的tableview。过去它一直运行良好,但最近由于某些搜索结果而开始崩溃。在这里,我的代码根据高尔夫球手的姓名,年龄和让分情况进行搜索。数据已正确加载到表中,我可以访问并向下钻取以接收更多信息。但是,当我输入“姓名”或“年龄”的搜索查询时,该应用程序将崩溃,而“高尔夫球手让分”返回的很好。

注意: dataSouceArray是表 View 的数据源,dataSourceArrayCopy是用于在搜索过滤器中添加和删除对象的数据的可变副本。

- (void)filterContentForSearchText:(NSString*)searchText scope:(NSString*)scope{
/*
Update the filtered array based on the search text and scope.
*/

[self.dataSourceArrayCopy removeAllObjects]; // First clear the filtered array.

/*
Search the main list for products whose type matches the scope (if selected) and whose name matches searchText; add items that match to the filtered array.
*/
for (Golfer *golfer in dataSourceArray){
if ([scope isEqualToString:@"Name"] || [golfer.golferName isEqualToString:scope]){
NSComparisonResult result = [golfer.golferName compare:searchText
options:(NSCaseInsensitiveSearch|NSDiacriticInsensitiveSearch)
range:NSMakeRange(0, [searchText length])];
if (result == NSOrderedSame){
[self.customerListCopy addObject:golfer];
}
}
if ([scope isEqualToString:@"Age"] || [golfer.golferAge isEqualToString:scope]){
NSComparisonResult result = [golfer.golferAge compare:searchText
options:(NSCaseInsensitiveSearch|NSDiacriticInsensitiveSearch)
range:NSMakeRange(0, [searchText length])];
if (result == NSOrderedSame){
[self.dataSourceArrayCopy addObject:golfer];
}
}
if ([scope isEqualToString:@"Handicap"] || [golfer.golferHandicap isEqualToString:scope])
{
NSComparisonResult result = [golfer.golferHandicap compare:searchText
options:(NSCaseInsensitiveSearch|NSDiacriticInsensitiveSearch)
range:NSMakeRange(0, [searchText length])];
if (result == NSOrderedSame)
{
[self.dataSourceArrayCopy addObject:golfer];
}
}
}
}
- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString
{
[self filterContentForSearchText:searchString scope:
[[self.searchDisplayController.searchBar scopeButtonTitles] objectAtIndex:[self.searchDisplayController.searchBar selectedScopeButtonIndex]]];

// Return YES to cause the search result table view to be reloaded.
return YES;
}


- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchScope:(NSInteger)searchOption
{
[self filterContentForSearchText:[self.searchDisplayController.searchBar text] scope:
[[self.searchDisplayController.searchBar scopeButtonTitles] objectAtIndex:searchOption]];

// Return YES to cause the search result table view to be reloaded.
return YES;
}

任何帮助,将不胜感激,谢谢您抽出宝贵的时间阅读本文。

最佳答案

奇怪的是,当在另一个开发人员电话上测试完全相同的代码时,它没有使程序崩溃。答案不多,但是让所有人都可以借鉴,并在多种设备上进行测试。

关于iphone - 返回结果时搜索显示 Controller 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2470774/

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