我正在尝试从Web服务检索数据,然后根据值过滤数据并将其存储在另一个数组中。但是,每当我尝试过滤它时,我都会收到以下错误:
***因未捕获的异常而终止应用 'NSInvalidArgumentException',原因:' - [__ NSCFDictionary Month]: 无法识别的选择器发送到实例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];
}
答案 0 :(得分:2)
您通过网络收到的数据很可能不是if ( videoMode ) {
$(document).click(function( ){
$( '.slider' ).muteYTPVolume( );
$( '.click-to-exit' ).hide( ).animate( { opacity: 0 }, { duration: 500, queue: false } );
$( videoModeSelector ).show( ).animate( { opacity: 1 }, { duration: 500, queue: false } );
videoMode = false;
});
}
类的实例。从错误日志中,它看起来实际上是EventsBean
对象。我猜它已经为你解析了JSON字符串。所以我可能会尝试通过NSDictionary
来访问month属性。
答案 1 :(得分:1)
for (EventsBean *item in datasource)
这里的数据源包含NSDictionaries的对象,而不是EventBeans的对象。
您需要解析该字典并创建EventsBean的对象
或
你需要做这样的事情
if([[item objectForKey:@"Month"] isEqualToString:monthString])