0
總之,我想我的tableView
顯示今天發生的事件(例如足球比賽)。因此,我想通過使用addObject
添加與NSMutableArray
匹配的那些字典。我已經使用此代碼試了一下,但NSMutableArray
不顯示任何東西:addObject to NSMutableArray無法正常工作
self.Array = [NSMutableArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"matches" ofType:@"plist"]];
matchesToday = [[NSMutableArray alloc] init];
match = [[NSMutableDictionary alloc] init];
for (int i=0; i<[Array count]; i++) {
NSDate *datum = [[Array objectAtIndex:i] objectForKey:@"date"];
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
[matchesToday addObject:match];
NSLog(@"%i, %@", i, otherDate);
NSLog(@"Match is today");
}
else {
NSLog(@"Match is not today");
}
}
NSLog(@"%@", matchesToday);
}
plist中是字典的一個數組,看起來像這樣:
<array>
<dict>
<key>date</key>
<date>2011-12-13T00:00:00Z</date>
<key>titel</key>
<string>Tilburg - Oss</string>
</dict>
<dict>
<key>date</key>
<date>2011-12-13T00:00:00Z</date>
<key>titel</key>
<string>Amsterdam - Roosendaal</string>
</dict>
</array>
我在做什麼錯?
這是什麼實際記錄? – 2011-12-13 20:42:44
在你的代碼中,`match`只不過是一個空字典。在`alloc`和`init`之後的任何時候,你都不會對'match`字典做任何事情。如果它在`// do something`註釋塊中,請添加它。 – 2011-12-13 20:52:26