English 中文(简体)
如何把精.的概览整理成今天、本周、下周等章节。 利用核心数据
原标题:how to sort uitableview with nsdate into sections of today, this week, next week etc. using core data

I can sort the table view in order of start date using the sort descriptors, but i want to group the sorted tableview into sections with dates for today in one section, dates for next week in another and so forth.

我发现这一员额是。 页: 1 今天,昨天,本周,即上周,即上月......变数,让我计算这些事件的日期。

页: 1

I can t figure out a way to organize the dates into these sections though. If anyone knows a post or sample code that does this, please let me know. Posting a sample code would be appreciated too.

This is what i m trying to achieve. enter image description here

Edit: I still haven t figured out exactly how to achieve this, but I ll post the progress so far.

I have can now accurately calculate the dates for this week, next week, etc..

这部法律是:

  NSCalendar *cal = [NSCalendar currentCalendar];
NSDate *today = [NSDate date];
[cal setLocale:[NSLocale currentLocale]];

NSDateComponents *nowComponents = [cal components:NSYearCalendarUnit | NSWeekCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit fromDate:today];
[nowComponents setHour:0]; //8a.m.
[nowComponents setMinute:0];
[nowComponents setSecond:0];


nowComponents = [cal components:NSYearCalendarUnit | NSMonthCalendarUnit fromDate:today];
[nowComponents setMonth: [nowComponents month]]; //This Month begins on


NSDate *thisMonthB = [cal dateFromComponents:nowComponents];

nowComponents = [cal components:NSYearCalendarUnit | NSWeekCalendarUnit fromDate:today];
[nowComponents setWeekday:2]; //Monday
[nowComponents setWeek: [nowComponents week] - 1]; //Last week began on

NSDate *lWeek = [cal dateFromComponents:nowComponents];

nowComponents = [cal components:NSYearCalendarUnit | NSWeekCalendarUnit fromDate:today];
[nowComponents setWeekday:2]; //Monday
[nowComponents setWeek: [nowComponents week]]; //This Week begins on

NSDate *tWeekB = [cal dateFromComponents:nowComponents];


nowComponents = [cal components:NSWeekdayCalendarUnit | NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit fromDate:today];
[nowComponents setDay: 0];  // Yesterday
NSDate *yesterday = [cal dateFromComponents:nowComponents];



nowComponents = [cal components:NSWeekdayCalendarUnit | NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit fromDate:today];
[nowComponents setDay: 1]; // Today
NSDate *tday = [cal dateFromComponents:nowComponents];


nowComponents = [cal components:NSWeekdayCalendarUnit | NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit fromDate:today];
[nowComponents setDay: +2]; // Tomorrow
NSDate *tom = [cal dateFromComponents:nowComponents];

nowComponents = [cal components:NSWeekdayCalendarUnit | NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit fromDate:today];
[nowComponents setDay: +3]; // Tomorrow ends on
NSDate *tomE = [cal dateFromComponents:nowComponents];


nowComponents = [cal components:NSYearCalendarUnit | NSWeekCalendarUnit fromDate:today];
[nowComponents setWeekday:2]; //Monday
[nowComponents setWeek: [nowComponents week] + 1]; //This Week ends on

NSDate *tWeekE = [cal dateFromComponents:nowComponents];



nowComponents = [cal components:NSYearCalendarUnit | NSWeekCalendarUnit fromDate:today];
[nowComponents setWeekday:2]; //Monday
[nowComponents setWeek: [nowComponents week] + 2]; //Next week end on


NSDate *nWeekE = [cal dateFromComponents:nowComponents];

nowComponents = [cal components:NSYearCalendarUnit | NSMonthCalendarUnit fromDate:today];
[nowComponents setMonth:[nowComponents month] + 1];//This Month ends on


NSDate *thisMonthE = [cal dateFromComponents:nowComponents];





NSLog(@"this month began on =%@",[NSDateFormatter localizedStringFromDate:thisMonthB dateStyle:NSDateFormatterMediumStyle timeStyle:NSDateFormatterShortStyle] );
NSLog(@"last week began on =%@",[NSDateFormatter localizedStringFromDate:lWeek dateStyle:NSDateFormatterMediumStyle timeStyle:NSDateFormatterShortStyle] );
NSLog(@"this week begin on =%@",[NSDateFormatter localizedStringFromDate:tWeekB dateStyle:NSDateFormatterMediumStyle timeStyle:NSDateFormatterShortStyle] );
NSLog(@"yesterday=%@",[NSDateFormatter localizedStringFromDate:yesterday dateStyle:NSDateFormatterMediumStyle timeStyle:NSDateFormatterShortStyle] );

NSLog(@"today=%@", [NSDateFormatter localizedStringFromDate:tday dateStyle:NSDateFormatterMediumStyle timeStyle:NSDateFormatterShortStyle]);
NSLog(@"tomorrow=%@",[NSDateFormatter localizedStringFromDate:tom dateStyle:NSDateFormatterMediumStyle timeStyle:NSDateFormatterShortStyle] );
NSLog(@"tomorrow ends on =%@",[NSDateFormatter localizedStringFromDate:tomE dateStyle:NSDateFormatterMediumStyle timeStyle:NSDateFormatterShortStyle] );
NSLog(@"this Week ends on =%@",[NSDateFormatter localizedStringFromDate:tWeekE dateStyle:NSDateFormatterMediumStyle timeStyle:NSDateFormatterShortStyle] );
NSLog(@"next Week ends on =%@",[NSDateFormatter localizedStringFromDate:nWeekE dateStyle:NSDateFormatterMediumStyle timeStyle:NSDateFormatterShortStyle] );
NSLog(@"this Month ends on=%@",[NSDateFormatter localizedStringFromDate:thisMonthE dateStyle:NSDateFormatterMediumStyle timeStyle:NSDateFormatterShortStyle] );

之后,关于联系的法典就稍有改动。 该法典更加可靠和准确。

现在,如果你在核心数据标目中创造财产,如具有国家抽样特性的Title节,然后建立一个由人管理的次级类别,那么你就可以为这一特性创造一种习惯。

.m file

  • (缩略语*) 标题:

    return @"Today"; }

以及在单列成果控制器中,如果你选择把这一特性留给单列成果控制员,就象这样把各款放在你们身上:

 [[NSFetchedResultsController alloc] 
 initWithFetchRequest:fetchRequest
 managedObjectContext:[self managedObjectContext]
 sectionNameKeyPath:@"sectionIdentifier"
 cacheName:@"cache"];

并将见该节。

问题在于表格中的观点方法、章节中的行文数目和标题。 我仅能说明如何将单列结果纳入表层中的定义部分。

如果任何人能够提供帮助,请这样做。 在如何实现这一目标方面,我失去了意义,在如何做到这一点方面似乎没有帮助或解决。

问题回答

你可以使用Erica Sandun ́s NSDate+Utilies等。 这将大大有助于。





相关问题
Code sign Error

I have created a new iPhone application.I have two mach machines. I have created the certificate for running application in iPhone in one mac. Can I use the other mac for running the application in ...

ABPersonViewController Usage for displaying contact

Created a View based Project and added a contact to the AddressBook using ABAddressBookRef,ABRecordRef now i wanted to display the added contact ABPersonViewController is the method but how to use in ...

将音频Clips从Peter改为服务器

我不禁要问,那里是否有任何实例表明从Peit向服务器发送音响。 I m不关心电话或SIP风格的解决办法,只是一个简单的袖珍流程......

• 如何将搜查线重新定位?

我正试图把图像放在搜索条左边。 但是,问题始于这里,搜索条线不能重新布署。

热门标签