我在本地存储了一个.json
文件,在加载文件路径之后,我将countries
加载到一个名为countries = (NSArray *)[NSJSONSerialization JSONObjectWithData [fileContents dataUsingEncoding:NSUTF8StringEncoding] options:0 error:NULL];
的数组中。.json
我将countries
加载到 NSString * filePath =[[NSBundle mainBundle] pathForResource:@"countries" ofType:@"json"];
NSError * error;
NSString* fileContents =[NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:&error];
if(error||!filePath)
{
NSLog(@"Error reading file: %@",error.localizedDescription);
}
countries = (NSArray *)[NSJSONSerialization
JSONObjectWithData:[fileContents dataUsingEncoding:NSUTF8StringEncoding]
options:0 error:NULL];
数组中作为:
NSMutableArray
在那之后,我采用了displayItems
displayItems = [[NSMutableArray alloc] initWithArray:countries];
并将其初始化为UITableView
。
与displayItems
代理方法相比,我count
使用了NSLog
248
后cellForRowAtIndexPath
代表didSelectRowAtIndexPath
意味着&#{1}} 39;正确获取值ViewController
和-(void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText{
if ([searchText length] == 0) {
[displayItems removeAllObjects];
[displayItems addObjectsFromArray:countries];
} else {
[displayItems removeAllObjects];
for (NSString *string in countries) {
NSRange r = [string rangeOfString:searchText options:NSCaseInsensitiveSearch];
if (r.location != NSNotFound) {
[displayItems addObject:string];
}
}
}
[tableView reloadData];
}
请参阅下面的图片,了解Range r
的层次结构
问题:
根据断点,这种方法正在产生问题。
unrecognized selector sent to instance
当它到达行UISearchBar
时,应用程序崩溃,错误为*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFDictionary rangeOfString:options:]: unrecognized selector sent to instance 0x12ddd5e90'
*** First throw call stack:
(0x180a55900 0x1800c3f80 0x180a5c61c 0x180a595b8 0x18095d68c 0x1000d0e3c 0x185953d28 0x18577fe50 0x18577fdcc 0x185767a88 0x185953ad4 0x18578a8f8 0x18591fee8 0x18591f104 0x185aafae4 0x186095b20 0x18591ee70 0x185b5cc90 0x185b5c854 0x185772e84 0x181417e20 0x180a0cefc 0x180a0c990 0x180a0a690 0x180939680 0x181e48088 0x1857b0d90 0x1000e0e94 0x1804da8b8)
libc++abi.dylib: terminating with uncaught exception of type NSException
。
一切都工作得很好,直到我在mciSendString("play mp3 wait", NULL, 0, NULL);
应用程序崩溃时输入一封信。
确切错误是:
mciSendString("pause mp3", NULL, 0, NULL);
mciSendString("stop mp3", NULL, 0, NULL);