出现异常 'NSInvalidArgumentException',原因:'-[__NSCFString stringValue]
getting exception 'NSInvalidArgumentException', reason: '-[__NSCFString stringValue]
我已经准备好通过 Google 尝试多种解决方案,但我遇到了两种错误,解决方案我得到了这个
2015-08-06 18:52:33.110 FastFast[2824:110493] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString stringValue]: unrecognized selector sent to instance 0x7f89c1eb7e50'
* First throw call stack:
但是当我没有应用任何解决方案时,我得到了这个
2015-08-06 19:09:24.473 FastFast[2933:117451] -[__NSCFNumber length]: unrecognized selector sent to instance 0xb000000000000003
2015-08-06 19:09:24.480 FastFast[2933:117451] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFNumber length]: unrecognized selector sent to instance 0xb000000000000003'
* First throw call stack:
我从 1 天开始就在弄乱这段代码,但没能找到真正的问题。
但是当我对这个函数设置静态限制时,一切都很好。
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
NSLog(@"Number Of Row %lu",_AddressArray.count);
return 4; // when set static limit here like this all works fine
return [self.temporaryAddArray count];}
下面link属于我的接口文件和实现文件
file.h
https://drive.google.com/file/d/0B85GTvLEHASFVDEwajA1YXp1aUE/view?usp=sharing
file.m
https://drive.google.com/file/d/0B85GTvLEHASFNEhzUnN1U25qaEk/view?usp=sharing
我们将不胜感激。
恐怕您的价值观不是您期望的那样。
看起来 "temporaryAddArray" 是 NSNumber 不是数组,其他东西不是 NSNumber 但它是 NSString。
在使用 objectForKey:
从 JSON 分配值之前,通过显示检查它们的类型:
NSLog(@"%@", [variable class]);
并确保他们在您的 JSON 中输入的内容符合预期,因为他们中的一些人没有。
如果您粘贴从 API 获得的 JSON 会有所帮助,然后我可以准确指出问题。
您需要确保您正在初始化 NSMutableArray
只需添加
self.temporaryAddArray = [[NSMutableArray alloc]init];
到
-(void)viewDidLoad;
应该可以解决您的问题。
self.temporaryAddArray = [tempAddress objectForKey:@"Android"];
问题来了...
- 首先检查 [tempAddress objectForKey:@"Android"] 是否包含数组值
从你的错误我认为 [tempAddress objectForKey:@"Android"] return 一个字符串值这就是为什么这个抛出错误..
确保 [tempAddress objectForKey:@"Android"] return 加载表视图后的 NaArray 值。
这样做会解决您的问题。
[AFRequestmanager POST:tempUrlAddress parameters:urlParams success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"Responce Parameter %@",responseObject);
NSDictionary *tempAddress= (NSDictionary *)responseObject;
[self.activityIndicatorView stopAnimating];
id android = [tempAddress objectForKey:@"Android"];
if (if([android isKindOfClass:[NSArray class]]){
//Is array
self.temporaryAddArray =[android mutableCopy];
[self.tableview reloadData];
}
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Errorsss parameters %@",error);
}];
最终在深入挖掘之后,在您的回答的帮助下,我将问题出在哪里。
Json responce is here
{"Android":[{"recip_code":"94541824","recip_fname":"","recip_lname":"","recip_add1":"hillsrtreat main road h.no. 3535","recip_img":"","recip_add2":"","recip_stateid":"new state","recip_cityid":"Dublin","result":"Success"},{"recip_code":"53843299","recip_fname":"","recip_lname":"","recip_add1":"rz x yes RR HDTV j deed ju","recip_img":"","recip_add2":"","recip_stateid":"Westmeath","recip_cityid":"Dublin","result":"Success"},{"recip_code":"11493834","recip_fname":"","recip_lname":"","recip_add1":"newdgbfh","recip_img":"","recip_add2":"","recip_stateid":"Westmeath","recip_cityid":"bobo2","result":"Success"},{"recip_code":"29376578","recip_fname":"","recip_lname":"","recip_add1":"edggvfhkyfv","recip_img":"","recip_add2":"","recip_stateid":"Dublin","recip_cityid":"bobo2","result":"Success"},{"recip_code":"22549638","recip_fname":"","recip_lname":"","recip_add1":"This ios address 34 street","recip_img":"","recip_add2":"","recip_stateid":0,"recip_cityid":0,"result":"Success"}]}
In given image there is a visualization of error in array, in 1st selection it shows an STRING and in 2nd selection there is integer value which is the reason of that brutal exception
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *CellIdentifier = @"addAddress";
AddressTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
@try {
NSDictionary *currentAddress = [self.AddressArray objectAtIndex:indexPath.row];
NSString *addTitle= [NSString stringWithFormat:@"%@%@",[currentAddress objectForKey:@"recip_add1"],[currentAddress objectForKey:@"recip_add2"]];
cell.lblAddress.text =addTitle;
cell.lblCity.text=[currentAddress objectForKey:@"recip_cityid"];
cell.lblRecipentCode.text=[currentAddress objectForKey:@"recip_code"];
// cell.lblState.text=[NSString stringWithFormat:@"%@",[[currentAddress objectForKey:@"recip_stateid"] stringValue]];
cell.lblState.text=[currentAddress objectForKey:@"recip_stateid"];
}
@catch (NSException *exception) {
NSLog(@" Exception hit %@",exception);
}
return cell;
}
一切正常,直到 (NSDictionary *currentAddress) return 字符串值,但在 cell.lblCity.text 与 Integr 值交互的位置显示异常。
thanks guys to give your important time and answer :)
我已经准备好通过 Google 尝试多种解决方案,但我遇到了两种错误,解决方案我得到了这个
2015-08-06 18:52:33.110 FastFast[2824:110493] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString stringValue]: unrecognized selector sent to instance 0x7f89c1eb7e50' * First throw call stack:
但是当我没有应用任何解决方案时,我得到了这个
2015-08-06 19:09:24.473 FastFast[2933:117451] -[__NSCFNumber length]: unrecognized selector sent to instance 0xb000000000000003 2015-08-06 19:09:24.480 FastFast[2933:117451] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFNumber length]: unrecognized selector sent to instance 0xb000000000000003' * First throw call stack:
我从 1 天开始就在弄乱这段代码,但没能找到真正的问题。 但是当我对这个函数设置静态限制时,一切都很好。
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
NSLog(@"Number Of Row %lu",_AddressArray.count);
return 4; // when set static limit here like this all works fine
return [self.temporaryAddArray count];}
下面link属于我的接口文件和实现文件
file.h https://drive.google.com/file/d/0B85GTvLEHASFVDEwajA1YXp1aUE/view?usp=sharing
file.m https://drive.google.com/file/d/0B85GTvLEHASFNEhzUnN1U25qaEk/view?usp=sharing
我们将不胜感激。
恐怕您的价值观不是您期望的那样。
看起来 "temporaryAddArray" 是 NSNumber 不是数组,其他东西不是 NSNumber 但它是 NSString。
在使用 objectForKey:
从 JSON 分配值之前,通过显示检查它们的类型:
NSLog(@"%@", [variable class]);
并确保他们在您的 JSON 中输入的内容符合预期,因为他们中的一些人没有。 如果您粘贴从 API 获得的 JSON 会有所帮助,然后我可以准确指出问题。
您需要确保您正在初始化 NSMutableArray
只需添加
self.temporaryAddArray = [[NSMutableArray alloc]init];
到
-(void)viewDidLoad;
应该可以解决您的问题。
self.temporaryAddArray = [tempAddress objectForKey:@"Android"];
问题来了...
- 首先检查 [tempAddress objectForKey:@"Android"] 是否包含数组值 从你的错误我认为 [tempAddress objectForKey:@"Android"] return 一个字符串值这就是为什么这个抛出错误..
确保 [tempAddress objectForKey:@"Android"] return 加载表视图后的 NaArray 值。
这样做会解决您的问题。
[AFRequestmanager POST:tempUrlAddress parameters:urlParams success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"Responce Parameter %@",responseObject);
NSDictionary *tempAddress= (NSDictionary *)responseObject;
[self.activityIndicatorView stopAnimating];
id android = [tempAddress objectForKey:@"Android"];
if (if([android isKindOfClass:[NSArray class]]){
//Is array
self.temporaryAddArray =[android mutableCopy];
[self.tableview reloadData];
}
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Errorsss parameters %@",error);
}];
最终在深入挖掘之后,在您的回答的帮助下,我将问题出在哪里。
Json responce is here {"Android":[{"recip_code":"94541824","recip_fname":"","recip_lname":"","recip_add1":"hillsrtreat main road h.no. 3535","recip_img":"","recip_add2":"","recip_stateid":"new state","recip_cityid":"Dublin","result":"Success"},{"recip_code":"53843299","recip_fname":"","recip_lname":"","recip_add1":"rz x yes RR HDTV j deed ju","recip_img":"","recip_add2":"","recip_stateid":"Westmeath","recip_cityid":"Dublin","result":"Success"},{"recip_code":"11493834","recip_fname":"","recip_lname":"","recip_add1":"newdgbfh","recip_img":"","recip_add2":"","recip_stateid":"Westmeath","recip_cityid":"bobo2","result":"Success"},{"recip_code":"29376578","recip_fname":"","recip_lname":"","recip_add1":"edggvfhkyfv","recip_img":"","recip_add2":"","recip_stateid":"Dublin","recip_cityid":"bobo2","result":"Success"},{"recip_code":"22549638","recip_fname":"","recip_lname":"","recip_add1":"This ios address 34 street","recip_img":"","recip_add2":"","recip_stateid":0,"recip_cityid":0,"result":"Success"}]}
In given image there is a visualization of error in array, in 1st selection it shows an STRING and in 2nd selection there is integer value which is the reason of that brutal exception
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *CellIdentifier = @"addAddress";
AddressTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
@try {
NSDictionary *currentAddress = [self.AddressArray objectAtIndex:indexPath.row];
NSString *addTitle= [NSString stringWithFormat:@"%@%@",[currentAddress objectForKey:@"recip_add1"],[currentAddress objectForKey:@"recip_add2"]];
cell.lblAddress.text =addTitle;
cell.lblCity.text=[currentAddress objectForKey:@"recip_cityid"];
cell.lblRecipentCode.text=[currentAddress objectForKey:@"recip_code"];
// cell.lblState.text=[NSString stringWithFormat:@"%@",[[currentAddress objectForKey:@"recip_stateid"] stringValue]];
cell.lblState.text=[currentAddress objectForKey:@"recip_stateid"];
}
@catch (NSException *exception) {
NSLog(@" Exception hit %@",exception);
}
return cell;
}
一切正常,直到 (NSDictionary *currentAddress) return 字符串值,但在 cell.lblCity.text 与 Integr 值交互的位置显示异常。
thanks guys to give your important time and answer :)