0
我有一個帶有搜索顯示控制器的tableview。它過去一直很好,但最近已經開始崩潰某些搜索結果。在這裏,我的代碼根據他們的姓名,年齡和障礙搜索高爾夫球員。數據被正確加載到表格中,我可以訪問和深入查看以獲取更多信息。但是,當我輸入名稱或年齡的搜索查詢時,應用程序崩潰,而高爾夫球手障礙返回正常。搜索顯示控制器在返回結果時崩潰
注:dataSouceArray
是用於實現代碼如下數據源,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;
}
任何幫助將不勝感激,感謝您花時間閱讀此。
粗略一瞥,我沒有看到任何明顯的錯誤。您需要設置斷點並逐步瀏覽代碼,以查找崩潰併發布的確切行。 – TechZen 2010-03-18 15:09:26
將來,請勿在代碼中使用製表符來縮進格式。 – TechZen 2010-03-18 15:20:28
謝謝你看看,我會稍後再報告。 – Convolution 2010-03-18 15:26:32