场景:
我有跟踪iOS应用程序的费用,我将费用从费用明细视图控制器存储到表视图(带有提取结果控制器),显示费用列表以及类别和金额和日期.我的实体"Money"中有一个日期属性,它是费用或收入的父实体.
我的问题:
我想要的是基本上分类给定的一周,一个月或一年的费用/收入,并将其显示为部分标题,例如:(10月1日至10月7日,2012年),它显示费用/收入金额和相关根据特定的一周的东西.在该视图中提供了两个按钮,如果我按下右键,它将使周增加一周(2012年10月1日至10月7日现在显示2012年10月8日 - 10月15日),同样左按钮将减少一周一个星期.我在视图中也有两个段控件.我想要做的是按下"每周"的段控制,如果我按下另一段"类别" - 我将如何根据类别过滤掉每周的费用/收入?
我想在表格视图中显示两个部分(一个显示费用的日期,另一个显示格式的收入日期(2012年10月1日 - 2012年10月7日)).我怎么做到这一点?我写了一些伪代码,如果有人能告诉我如何完成上述操作,那就太好了.
编辑 - FETCH控制器
- (void)userDidSelectStartDate:(NSDate *)startDate andEndDate:(NSDate *)endDate
{
AppDelegate * applicationDelegate = (AppDelegate *) [[UIApplication sharedApplication] delegate];
NSManagedObjectContext * context = [applicationDelegate managedObjectContext];
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
// Edit the entity name as appropriate.
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Money" inManagedObjectContext:context];
[fetchRequest setEntity:entity];
[NSFetchedResultsController deleteCacheWithName:nil];
//Here you create the predicate that filters the results to only show the ones with the selected date
NSPredicate *predicate = [NSPredicate …Run Code Online (Sandbox Code Playgroud) 场景:
我有跟踪iOS应用程序的费用,我将费用从费用明细视图控制器存储到表视图(带有提取结果控制器),显示费用列表以及类别和金额和日期.我的实体"Money"中有一个日期属性,它是费用或收入的父实体.
题:
我想要的是基本上按月分类我的费用并将其显示为部分标题,例如:(2012年11月1日 - 11月30日),它显示根据特定月份的费用金额和相关的东西.在该视图中提供了两个按钮,如果我按下右按钮,它将使月份增加一个月(2012年12月1日 - 12月31日),同样左按钮会将月份减少一个月.
我怎么做到这一点?我正在尝试以下代码 - 这有点工作.假设我的当前部分标题为(2012年11月1日 - 11月30日),当我按下左按钮时,它给出了截面标题(2012年10月1日 - 10月30日),这是错误的,它应该是2012年10月31日而不是2012年10月30日.
- (NSDate *)firstDateOfTheMonth
{
self.startDate = [NSDate date];
NSCalendar* calendar = [NSCalendar currentCalendar];
[calendar setTimeZone:[NSTimeZone localTimeZone]];
NSDateComponents* components = [calendar components:NSYearCalendarUnit|NSMonthCalendarUnit|NSDayCalendarUnit fromDate:self.startDate];
[components setDay:1];
firstDateOfTheMonth = [[calendar dateFromComponents:components] retain];
return firstDateOfTheMonth;
}
- (NSDate *)lastDateOfTheMonth
{
NSCalendar* calendar = [NSCalendar currentCalendar];
[calendar setTimeZone:[NSTimeZone localTimeZone]];
NSDateComponents* components = [calendar components:NSYearCalendarUnit|NSMonthCalendarUnit|NSDayCalendarUnit fromDate:firstDateOfTheMonth];
[components setMonth:[components month]+1];
[components setDay:0];
lastDateOfTheMonth = [[calendar dateFromComponents:components] retain];
return lastDateOfTheMonth;
}
Run Code Online (Sandbox Code Playgroud)
然后我有一个名为"monthCalculation"的方法,我在其中调用上述两种方法.
- …Run Code Online (Sandbox Code Playgroud)