【发布时间】:2011-11-16 20:58:45
【问题描述】:
在一个 plist 中,我在一个数组中有几个字典(事件,例如足球比赛),如下所示:
<dict>
<key>date</key>
<date>2011-11-24T00:00:00Z</date>
<key>title</key>
<string>Amsterdam - Roosendaal</string>
</dict>
<dict>
<key>date</key>
<date>2012-06-25T00:00:00Z</date>
<key>title</key>
<string>Rotterdam - Utrecht</string>
</dict>
我有一个表格视图,其中有名为“今天”和“明天”的部分。现在,每当今天发生事件时,我都希望在“今天”部分看到它,而当活动计划在明天发生时,我希望在“明天”部分看到它。
编辑:我现在有这个代码:
self.Array = [NSMutableArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"matches" ofType:@"plist"]];
for (int i=0; i<[Array count]; i++) {
NSDate *datum = [[Array objectAtIndex:i] objectForKey:@"datum"];
NSCalendar *cal = [NSCalendar currentCalendar];
NSDateComponents *components = [cal components: (NSEraCalendarUnit|NSYearCalendarUnit|NSMonthCalendarUnit|NSDayCalendarUnit) fromDate:[NSDate date]];
NSDate *today = [cal dateFromComponents:components];
components = [cal components:(NSEraCalendarUnit|NSYearCalendarUnit|NSMonthCalendarUnit|NSDayCalendarUnit) fromDate:datum];
NSDate *otherDate = [cal dateFromComponents:components];
if([today isEqualToDate:otherDate]) {
//do stuff
NSLog(@"%i, %@", i, otherDate);
NSLog(@"Match is today");
}
else {
NSLog(@"Match is not today");
}
从 NSLog 看来,它以正确的方式进行了比较。但是,我现在想在一个部分中显示那些具有今天日期的字典。我想我因此必须创建一个数组(也许通过在“//do stuff”区域添加东西,例如addObject?)对此有什么想法吗?
【问题讨论】:
标签: iphone objective-c ios xcode