ios - 由于未捕获的异常,SIGABRT 终止应用程序

标签 ios json uitableview nsdata

我正在尝试从 Web 服务检索数据,然后过滤数据并根据值将其存储在另一个数组中。但是,每当我尝试过滤它时,我都会收到以下错误:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFDictionary Month]: unrecognized selector sent to instance 0x174079640'

这是我的代码:

- (void)getDataHTTPClient:(Client *)client didUpdateWithData:(id)data
{
    [self.view setUserInteractionEnabled:YES];

    if (isPullRefresh)
    {
        isPullRefresh = NO;
        [datasource removeAllObjects];
        [self.pullToRefreshView finishLoading];
    }

    NSMutableArray *array = (NSMutableArray *)data;
    if (![array count])
    {
        isNewsEnded = YES;
        [self.tableView reloadData];
        return;
    }
    [hud hide:YES];

    [datasource addObjectsFromArray:(NSMutableArray *) data];
    NSDate *currentDate = [NSDate date];
    NSCalendar* calendar = [NSCalendar currentCalendar];
    NSDateComponents* components = [calendar         components:NSYearCalendarUnit|NSMonthCalendarUnit|NSDayCalendarUnit fromDate:currentDate];
    monthInt= [components month];
    NSLog(@"month %li", monthInt);
    NSLog(@"month after deduction %li", monthInt-1);

    monthString = [NSString stringWithFormat:@"%zd",monthInt];

    for (EventsBean *item in datasource)
    {
        if([item.Month isEqualToString:monthString])
        {
            [filteredArray addObject:item];
        }
    }
    [self.tableView reloadData];

    if ([datasource count])
    {
        [self displayNoRecordMSG:NO];
    }
    else
    {
        [self displayNoRecordMSG:YES];
    }
}

错误显示在这一行

 if([item.Month isEqualToString:monthString])
{
    [filteredArray addObject:item];
}

最佳答案

您通过网络收到的数据很可能不是 EventsBean 类的实例。从错误日志来看,它实际上是一个 NSDictionary 对象。我猜它已经为您从 JSON 字符串中解析出来了。所以我可能会尝试通过 item[@"Month"] 来访问 month 属性。

关于ios - 由于未捕获的异常,SIGABRT 终止应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33362833/

相关文章:

JSON 架构生成器程序

ios - UITableViewCell 副标题不显示

ios - UIButton 在 setImage : is called 后不更新它的图像

ios - 如何在 Heroku 上运行云代码?

ios - 库和项目中的类名相同

iphone - 如何防止奇怪的滚动条闪烁?

ios - 如何在滚动时突出显示/更改表格 View 部分标题的背景颜色

ios - 警告 : Attempt to present whose view is not in the window hierarchy! 使用已识别的 segue 时

javascript - 在 JavaScript 中解析带有双引号的格式错误的 JSON

json - 如何使用 fetch 将 json 添加到主干、js 集合