首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从字典中得不到正确的信息

从字典中得不到正确的信息
EN

Stack Overflow用户
提问于 2013-12-17 16:01:50
回答 1查看 197关注 0票数 0

我正在使用MBCalendarKit并让它正常工作,但是我尝试对我创建的每个事件使用信息字典,在日历视图中选择一个事件之后,在细节页面上显示详细信息。我的事件都是从一个plist文件创建的:

这里是我创建事件的地方:

代码语言:javascript
复制
// 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];
        }
    }

下面是选择事件时发生的事情的代码:

代码语言:javascript
复制
- (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文件中最后一个事件的详细信息,因此无论选择哪个事件,细节总是说圣安东尼奥,TX。

我已将detail.details = _information; detail.details = [event.info objectForKey:@"Info"]; 改为detail.details = [event.info objectForKey:@"Info"];,但这导致了 -[__NSCFString objectForKey:]: unrecognized selector sent to instance 0xbcc2000

EN

回答 1

Stack Overflow用户

发布于 2013-12-17 16:48:30

我通过更改一些- (void)calendarView:(CKCalendarView *)CalendarView didSelectEvent:(CKCalendarEvent *)event;方法使其工作。

下面是用于选择事件的工作代码:

代码语言:javascript
复制
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];
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20638899

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档