我正在使用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文件中最后一个事件的详细信息,因此无论选择哪个事件,详细信息总是说圣安东尼奥,德克萨斯州。
我已将detail.details = _information;
更改为detail.details = [event.info objectForKey:@"Info"];
但是,这会导致-[__NSCFString objectForKey:]: unrecognized selector sent to instance 0xbcc2000
答案 0 :(得分:0)
我通过更改- (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];
_information = [NSString stringWithFormat:@"%@", event.info];
detail.details = _information;
detail.eventTitle = event.title;
detail.eventDate = [dateformatter stringFromDate:event.date];
[self.navigationController pushViewController:detail animated:YES];