我試圖從Web服務中檢索數據,然後過濾數據並將其存儲在另一個基於值的數組中。不過,我得到以下錯誤,每當我嘗試對其進行過濾:SIGABRT由於未捕獲的異常而終止應用程序
*** 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];
}
請登錄'data'和'datasource'的價值。你得到錯誤的物品類型。 – anhtu
'datasource'數組的內容是什麼以及它是如何填充的? –
'item'看起來像是一個NSDictionary - 也許你想'item [@「month」]'?數據源是一個包含EventsBean對象的可變數組。它從webserivce填充。 – Paulw11