'NSInvalidArgumentException '-[NSTaggedPointerString 计数]:无法识别的选择器发送到实例 0xa006162696a614e6'
'NSInvalidArgumentException '-[NSTaggedPointerString count]: unrecognized selector sent to instance 0xa006162696a614e6'
我是新手,设计天气预报应用程序是我在 iOS 的第一个项目。
我设计了一个UISearchBar
来搜索城市名称。搜索栏的工作方式为:
1) 第 1 步: 输入 "Naji"。它在 table 视图中显示了两个城市:
名治
纳吉
2) 第 2 步: 输入 "Najib"。它没有显示任何结果,因为结果为空。
(错误部分)
3) 第 3 步: 每当我输入 "Najib" 时,应用程序终止并出现以下错误:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSTaggedPointerString count]:
unrecognized selector sent to instance 0xa006162696a614e6'
密码是:
-(void)searchBar:(UISearchBar *)asearchBar textDidChange:(NSString *)searchText{
if ([searchText length] <= return;
if ([searchText length]==0) {
[discityname removeAllObjects];
[discityname addObjectsFromArray:cityname];
}else{
[discityname removeAllObjects];
NSURLSession *session=[NSURLSession sharedSession];
NSString *complete_url=[NSString stringWithFormat:@"https://query.yahooapis.com/v1/public/yql?q=select%%20*%%20from%%20geo.places%%20where%%20text%%3D%%22%@%%25%%22&format=json&diagnostics=true&callback=",searchText];
NSURLSessionDataTask *dataTask=[session dataTaskWithURL:[NSURL URLWithString:complete_url]completionHandler:^(NSData *data, NSURLResponse *response, NSError *error){
NSDictionary *json=[NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
NSLog(@"%@",json);
NSMutableDictionary *currentDict = [[NSMutableDictionary alloc]initWithDictionary:json[@"query"]];
int a=[[currentDict valueForKey:@"count"] intValue];
if (a!=0) {
cityname=[[NSMutableArray alloc]init];
// if ([currentDict valueForKey: @"results"] != [NSNull null])
// {
NSMutableDictionary *conDict = [[NSMutableDictionary alloc]initWithDictionary:currentDict[@"results"]];
NSMutableArray *places=[conDict valueForKey:@"place"];
NSMutableArray *country=[places valueForKey:@"country"];
NSMutableArray *countryname=[country valueForKey:@"content"];
NSMutableArray *placeName= [places valueForKey:@"name"];
NSMutableArray *centroid=[places valueForKey:@"centroid"];
NSMutableArray *latitude=[centroid valueForKey:@"latitude"];
NSMutableArray *longitude=[centroid valueForKey:@"longitude"];
//if ([placeName isKindOfClass:[NSMutableArray class]]) {
//}
//cityname=[[NSMutableArray alloc]initWithArray:placeName];
NSLog(@"%lu",placeName.count);
for (int i=0; i<placeName.count; i++) {
[cityname addObject:[placeName objectAtIndex:i]];
[countrynames addObject:[countryname objectAtIndex:i]];
}
dispatch_async(dispatch_get_main_queue(), ^{
discityname=[[NSMutableArray alloc]initWithArray:cityname];
discountryname=[[NSMutableArray alloc]initWithArray:countrynames];
latitudenames=[[NSMutableArray alloc]initWithArray:latitude];
longitudenames=[[NSMutableArray alloc]initWithArray:longitude];
[tableView reloadData];
});
}
// for(int i=0;i<[placeName count];i++)
//i NSLog(@"The place is: %@ , %@, %@, %@",placeName[i],countryname[i],latitude[i],longitude[i]);
}];
[dataTask resume];
for (NSString *string in discityname) {
NSRange r=[string rangeOfString:searchText options:NSCaseInsensitiveSearch];
if (r.location!=NSNotFound) {
[discityname addObject:string];
}
}
}
[tableView reloadData];
}
答案:它应该显示 json 中返回的城市名称 "Najib"。
你可以在Xcode中添加异常断点,它会告诉你哪一行崩溃了
在Xcode中,打开左侧面板,转到显示断点导航器,在左下角,单击加号图标并添加异常断点.
我是新手,设计天气预报应用程序是我在 iOS 的第一个项目。
我设计了一个UISearchBar
来搜索城市名称。搜索栏的工作方式为:
1) 第 1 步: 输入 "Naji"。它在 table 视图中显示了两个城市: 名治 纳吉
2) 第 2 步: 输入 "Najib"。它没有显示任何结果,因为结果为空。
(错误部分)
3) 第 3 步: 每当我输入 "Najib" 时,应用程序终止并出现以下错误:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSTaggedPointerString count]: unrecognized selector sent to instance 0xa006162696a614e6'
密码是:
-(void)searchBar:(UISearchBar *)asearchBar textDidChange:(NSString *)searchText{
if ([searchText length] <= return;
if ([searchText length]==0) {
[discityname removeAllObjects];
[discityname addObjectsFromArray:cityname];
}else{
[discityname removeAllObjects];
NSURLSession *session=[NSURLSession sharedSession];
NSString *complete_url=[NSString stringWithFormat:@"https://query.yahooapis.com/v1/public/yql?q=select%%20*%%20from%%20geo.places%%20where%%20text%%3D%%22%@%%25%%22&format=json&diagnostics=true&callback=",searchText];
NSURLSessionDataTask *dataTask=[session dataTaskWithURL:[NSURL URLWithString:complete_url]completionHandler:^(NSData *data, NSURLResponse *response, NSError *error){
NSDictionary *json=[NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
NSLog(@"%@",json);
NSMutableDictionary *currentDict = [[NSMutableDictionary alloc]initWithDictionary:json[@"query"]];
int a=[[currentDict valueForKey:@"count"] intValue];
if (a!=0) {
cityname=[[NSMutableArray alloc]init];
// if ([currentDict valueForKey: @"results"] != [NSNull null])
// {
NSMutableDictionary *conDict = [[NSMutableDictionary alloc]initWithDictionary:currentDict[@"results"]];
NSMutableArray *places=[conDict valueForKey:@"place"];
NSMutableArray *country=[places valueForKey:@"country"];
NSMutableArray *countryname=[country valueForKey:@"content"];
NSMutableArray *placeName= [places valueForKey:@"name"];
NSMutableArray *centroid=[places valueForKey:@"centroid"];
NSMutableArray *latitude=[centroid valueForKey:@"latitude"];
NSMutableArray *longitude=[centroid valueForKey:@"longitude"];
//if ([placeName isKindOfClass:[NSMutableArray class]]) {
//}
//cityname=[[NSMutableArray alloc]initWithArray:placeName];
NSLog(@"%lu",placeName.count);
for (int i=0; i<placeName.count; i++) {
[cityname addObject:[placeName objectAtIndex:i]];
[countrynames addObject:[countryname objectAtIndex:i]];
}
dispatch_async(dispatch_get_main_queue(), ^{
discityname=[[NSMutableArray alloc]initWithArray:cityname];
discountryname=[[NSMutableArray alloc]initWithArray:countrynames];
latitudenames=[[NSMutableArray alloc]initWithArray:latitude];
longitudenames=[[NSMutableArray alloc]initWithArray:longitude];
[tableView reloadData];
});
}
// for(int i=0;i<[placeName count];i++)
//i NSLog(@"The place is: %@ , %@, %@, %@",placeName[i],countryname[i],latitude[i],longitude[i]);
}];
[dataTask resume];
for (NSString *string in discityname) {
NSRange r=[string rangeOfString:searchText options:NSCaseInsensitiveSearch];
if (r.location!=NSNotFound) {
[discityname addObject:string];
}
}
}
[tableView reloadData];
}
答案:它应该显示 json 中返回的城市名称 "Najib"。
你可以在Xcode中添加异常断点,它会告诉你哪一行崩溃了 在Xcode中,打开左侧面板,转到显示断点导航器,在左下角,单击加号图标并添加异常断点.