我正在使用 MBCalendarKit 并使其正常工作,但我正在尝试为我创建的每个事件使用信息字典,以便在日历视图中选择事件后在详细信息页面上显示详细信息。我的事件都是从 plist 文件创建的:
这是我创建事件的地方:
// Read Events.plist
NSString *path = [[NSBundle mainBundle] pathForResource:@"Events" ofType:@"plist"];
NSDictionary *dictPri = [[NSMutableDictionary alloc]initWithContentsOfFile:path];
NSMutableArray *arrEvents = [[NSMutableArray alloc] initWithArray:[dictPri objectForKey:@"List"]];
// Loop through each item in List array of Events.plist
for (NSDictionary *dict in arrEvents)
{
NSString *titleString = nil;
NSString *date = nil;
titleString = [NSString stringWithFormat:@"%@",[dict objectForKey:@"Title"]];
date = [NSString stringWithFormat:@"%@",[dict objectForKey:@"Date"]];
// Create events
aCKCalendarEvent = [[CKCalendarEvent alloc] init];
aCKCalendarEvent.title = titleString;
aCKCalendarEvent.date = [dateformatter dateFromString: date];
aCKCalendarEvent.info = [dict objectForKey:@"Info"];
_information = [NSString stringWithFormat:@"%@", aCKCalendarEvent.info];
BOOL dateExists;
for (int i = 0; i < [eventsArray count]; i++)
{
if ([[(CKCalendarEvent *)[eventsArray objectAtIndex:i]date]isEqualToDate:aCKCalendarEvent.date])
{
// Array already contains object with this date
dateExists = YES;
}
else
{
dateExists = NO;
}
NSLog(@"%c", dateExists);
}
if (dateExists == YES)
{
[eventsArray addObject:aCKCalendarEvent];
[_eventsDict setObject:eventsArray forKey:aCKCalendarEvent.date];
}
else
{
eventsArray = [[NSMutableArray alloc]init];
[eventsArray addObject:aCKCalendarEvent];
[_eventsDict setObject:eventsArray forKey:aCKCalendarEvent.date];
}
}
这是选择事件时发生的代码:
- (void)calendarView:(CKCalendarView *)CalendarView didSelectEvent:(CKCalendarEvent *)event;
{
NSDateFormatter *dateformatter = [[NSDateFormatter alloc] init];
[dateformatter setDateFormat:@"MM/dd/yyyy"];
EventDetail *detail = [[EventDetail alloc] initWithNibName:nil bundle:nil];
detail.details = _information;
detail.eventTitle = event.title;
detail.eventDate = [dateformatter stringFromDate:event.date];
[self.navigationController pushViewController:detail animated:YES];
我的问题是详细视图上显示的详细信息始终是 plist 文件中最后一个事件的详细信息,因此无论选择哪个事件,详细信息总是说 San Antonio, TX。
我已经变成detail.details = _information;
了detail.details = [event.info objectForKey:@"Info"];
但是,这导致-[__NSCFString objectForKey:]: unrecognized selector sent to instance 0xbcc2000