gpt4 book ai didi

ios - 'NSInvalidArgumentException '-[NSTaggedPointerString count]: unrecognized selector sent to instance 0xa006162696a614e6'

转载 作者:行者123 更新时间:2023-12-02 00:25:18 31 4
gpt4 key购买 nike

我是一名新手,正在设计一个天气预报应用程序作为我在 iOS 中的第一个项目。

我设计了一个UISearchBar来搜索城市名称。搜索栏的工作方式如下:

1) 第 1 步: 输入“Naji”。它在表格 View 中显示两个城市:纳吉纳吉

2) 第 2 步: 输入“纳吉”。它没有显示任何内容,因为结果为空。

(错误部分)

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 中,打开左侧面板,转到显示断点导航器,在左下角单击加号图标并添加异常断点

exception breakpoint in Xcode

关于ios - 'NSInvalidArgumentException '-[NSTaggedPointerString count]: unrecognized selector sent to instance 0xa006162696a614e6',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45161878/

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