您可以創建只返回費用在給定範圍內的請求:
//Not tested
NSDateComponents* comps = [[NSDateComponents alloc] init];
NSCalendar* cal = [NSCalendar currentCalendar];
NSInteger year,month;//set these as you like
[comps setYear:year];
[comps setMonth:month];
NSDate* start = [cal dateFromComponents:comps];
month += 1;
month = (month <= 12 ? : 1);
[comps setMonth:month];
NSDate* end = [cal dateFromComponents:comps];
NSPredicate* predicate = [NSPredicate predicateWithFormat:@"date > %@ AND date < %@",start,end];
NSFetchRequest* request = [[NSFetchRequest alloc] initWithEntityName:@"Expense"];
[request setPredicate:predicate];
然後用NSFetchedResultsController
來填充表視圖
感謝您的回答,但從您的解決方案中,您知道獲取數據之前的年份和月份。但是首先應該從數據中讀取年份和月份。不是嗎? :)無論如何,我認爲我可以做到,非常感謝! – JimZ 2013-05-14 00:32:44