【问题标题】:getting exception 'NSInvalidArgumentException', reason: '-[__NSCFString stringValue]得到异常'NSInvalidArgumentException',原因:'-[__NSCFString stringValue]
【发布时间】:2015-08-07 05:42:06
【问题描述】:

我已经准备好通过谷歌尝试多种解决方案,但我得到了两种错误,解决方案我得到了这个

2015-08-06 18:52:33.110 FastFast[2824:110493] * 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[__NSCFString stringValue]:无法识别的选择器发送到实例 0x7f89c1eb7e50” * 首先抛出调用栈:

但是当我没有应用任何解决方案时,我就会得到这个

2015-08-06 19:09:24.473 FastFast[2933:117451] -[__NSCFNumber 长度]:无法识别的选择器发送到实例 0xb000000000000003 2015-08-06 19:09:24.480 FastFast[2933:117451] * 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[__NSCFNumber 长度]:无法识别的选择器发送到实例 0xb000000000000003” * 首先抛出调用栈:

我从 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];}

下面的链接属于我的接口文件和实现文件

文件.h https://drive.google.com/file/d/0B85GTvLEHASFVDEwajA1YXp1aUE/view?usp=sharing

文件.m https://drive.google.com/file/d/0B85GTvLEHASFNEhzUnN1U25qaEk/view?usp=sharing

我们将不胜感激。

【问题讨论】:

  • File.m 无法打开,请检查temporaryAddArray 声明
  • 我已经检查过 file.m 是可访问的,并且temporaryAddArray没有任何问题有json的响应。
  • {"Android":[{"recip_code":"94541824","re​​cip_fname":"","re​​cip_lname":"","re​​cip_add1":"hillsrtreat 主路 h.no. 3535 ","re​​cip_img":"","re​​cip_add2":"","re​​cip_stateid":"新州","re​​cip_cityid":"都柏林","re​​sult":"成功"},{"recip_code":"11493834" ,"recip_fname":"","re​​cip_lname":"","re​​cip_add1":"newdgbfh","re​​cip_img":"","re​​cip_add2":"","re​​cip_stateid":"Westmeath","re​​cip_cityid":" bobo2","re​​sult":"成功"}]}

标签: ios tableview afnetworking viewcontroller


【解决方案1】:

恐怕您的价值观不是您期望的那种类型。 看起来“temporaryAddArray”是 NSNumber 而不是数组,其他东西不是 NSNumber 但它是 NSString。 在使用 objectForKey: 从 JSON 分配值之前,请通过显示检查它们的类型:

NSLog(@"%@", [variable class]);

并确保他们在您的 JSON 中有预期的类型,因为其中一些没有。 如果您粘贴从 API 获得的 JSON,这将有所帮助,然后我可以准确指出问题。

【讨论】:

  • {"Android":[{"recip_code":"94541824","re​​cip_fname":"","re​​cip_lname":"","re​​cip_add1":"hillsrtreat 主路 h.no. 3535 ","re​​cip_img":"","re​​cip_add2":"","re​​cip_stateid":"新州","re​​cip_cityid":"都柏林","re​​sult":"成功"}]}
【解决方案2】:

你需要确保你正在初始化你的 NSMutableArray

只需添加

self.temporaryAddArray = [[NSMutableArray alloc]init];

-(void)viewDidLoad;

应该可以解决您的问题。

【讨论】:

    【解决方案3】:

    self.temporaryAddArray = [tempAddress objectForKey:@"Android"];

    问题来了……

    • 首先检查 [tempAddress objectForKey:@"Android"] 是否包含数组值 根据您的错误,我认为 [tempAddress objectForKey:@"Android"] 返回一个字符串值,这就是抛出错误的原因..

    确保 [tempAddress objectForKey:@"Android"] 在加载 tableview 后返回 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);
        }];
    

    【讨论】:

    • 我检查了它,它返回 NSarray。下面的 json 响应 {"Android":[{"recip_code":"94541824","re​​cip_fname":"","re​​cip_lname":"","re​​cip_add1":"hillsrtreat 主路 h.no. 3535","re​​cip_img" :"","re​​cip_add2":"","re​​cip_stateid":"新州","re​​cip_cityid":"都柏林","re​​sult":"成功"}]}
    【解决方案4】:

    经过非常深入的挖掘,在您的回答的帮助下,我总结出问题出在哪里。

    Json 响应在这里 {"Android":[{"recip_code":"94541824","re​​cip_fname":"","re​​cip_lname":"","re​​cip_add1":"hillsrtreat 主路 h.no. 3535","re​​cip_img":"" ,"recip_add2":"","re​​cip_stateid":"新州","re​​cip_cityid":"Dublin","re​​sult":"Success"},{"recip_code":"53843299","re​​cip_fname":"", "recip_lname":"","re​​cip_add1":"rz x yes RR HDTV j deed ju","re​​cip_img":"","re​​cip_add2":"","re​​cip_stateid":"Westmeath","re​​cip_cityid":"都柏林","结果":"成功"},{"recip_code":"11493834","re​​cip_fname":"","re​​cip_lname":"","re​​cip_add1":"newdgbfh","re​​cip_img":""," recip_add2":"","re​​cip_stateid":"Westmeath","re​​cip_cityid":"bobo2","re​​sult":"Success"},{"recip_code":"29376578","re​​cip_fname":"","re​​cip_lname" :"","re​​cip_add1":"edggvfhkyfv","re​​cip_img":"","re​​cip_add2":"","re​​cip_stateid":"都柏林","re​​cip_cityid":"bobo2","re​​sult":"成功"} ,{"recip_code":"22549638","re​​cip_fname":"","re​​cip_lname":"","re​​cip_add1":"这个ios地址34街","re​​cip_img":"","re​​cip_add2":"", "recip_stateid":0,"recip_cityid":0,"result":"成功"}]}

    Image Link of json analysis

    在给定的图像中,数组中有错误的可视化,在第一个选择中它显示一个 STRING,在第二个选择中,有一个整数值,这就是那个残酷异常的原因

    - (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) 返回字符串值之前,一切正常,但在 cell.lblCity.text 与 Integr 值交互时,它会显示异常。

    感谢大家给予您重要的时间和回答:)

    【讨论】:

      猜你喜欢
      • 2015-12-24
      • 1970-01-01
      • 2013-04-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多