我已将 SearchBar 功能添加到我的 tableview 中。(注意我将 SearchBar 拖到 View 而不是 TableView 上)。我有以下子进程,当它到达 NSRange 函数时,它会引发异常错误以使我的程序崩溃。下面是我的SearchBar
方法。你能看到任何可能导致错误的东西吗?(我在下面包含了调试屏幕的摘录)
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText{
if (searchText.length==0){
boolIsFiltered = NO;
}
else
{
boolIsFiltered = YES;
arrayFilteredproducts = [[NSMutableArray alloc]init];
for (NSString *str in arrayProducts) {
NSRange stringRange = [str rangeOfString:searchText options:NSCaseInsensitiveSearch];
if (stringRange.location!=NSNotFound){
[arrayFilteredproducts addObject:str];
}
}
}
}
这是创建arrayProducts
.
- (void)request:(SFRestRequest *)request didLoadResponse:(id)jsonResponse {
NSMutableArray *records = [jsonResponse objectForKey:@"records"];
arrayProducts = records;
[self.tableProducts reloadData];
}
这是来自调试屏幕的转储:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSDictionaryM rangeOfString:options:]: unrecognized selector sent to instance 0x176c5a80 First throw call stack:
(0x30076f8b 0x3a5166af 0x3007a927 0x3007920b'