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>
は私が間違って何をしているのですか?あなたはif文の次の行に日付テスト内の配列から個々の項目を追加する必要が
実際にどのようなログを記録していますか? –
あなたのコードでは、 'match'は空の辞書に過ぎません。 'alloc'と' init'を実行した後、あなたは 'match'辞書を使って何もしません。それが '//do something'コメントブロックにある場合は、それを追加してください。 –
いいえ、私は本当に「マッチ」と何もしていません。私はplistからの辞書に対応するために '一致'したい。これは問題でなければなりません。私は 'NSMutableArray * match = [Array .....'のような何かをすべきだと思います。 – user1048042