• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

ios - 使用 MBCalendarKit 创建事件的问题

[复制链接]
菜鸟教程小白 发表于 2022-12-13 05:44:13 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

我在我的应用程序中使用 MBCalendarKit,我可以创建这样的事件:

CKCalendarEvent* aCKCalendarEvent = [[CKCalendarEvent alloc] init];
    [_infoDict setObject"Joint Meetings with KY State Horticulture Society, KY Vegetable Growers Association, KY Vineyard Society, and KY Farmer Market Association \nEmbassy Suites\nLexington, KY" forKey"Jan Joint"];
    aCKCalendarEvent.date = [dateformatter dateFromString: @"01/06/2014"];
    aCKCalendarEvent.title = @"Joint Meetings";
    aCKCalendarEvent.info = [_infoDict objectForKey"Jan Joint"];
    [eventsArray addObject: aCKCalendarEvent];
    [_eventsDict setObject: eventsArray forKey: [NSDate dateWithDay:06 month:01 year:2014]];

我可以像这样在同一天创建另一个事件:

[_infoDict setObject"Washington, D.C." forKey"Congress Convenes"];
    aCKCalendarEvent = [[CKCalendarEvent alloc] init];
    aCKCalendarEvent.date = [dateformatter dateFromString: @"01/06/2014"];
    aCKCalendarEvent.title = @"113th Congress Convenes";
    [eventsArray addObject: aCKCalendarEvent];
    [_eventsDict setObject: eventsArray forKey: [NSDate dateWithDay:06 month:01 year:2014]];

然后我可以像这样在不同的日子创建另一个事件:

eventsArray = [[NSMutableArray alloc] init];
    [_infoDict setObject"Hilton Hotel \nMemphis, TN" forKey"Forage & Grassland"];
    aCKCalendarEvent = [[CKCalendarEvent alloc] init];
    aCKCalendarEvent.date = [dateformatter dateFromString: @"01/12/2014"];
    aCKCalendarEvent.title = @"American Forage & Grassland Council Annual Conference";
    [eventsArray addObject: aCKCalendarEvent];
    [_eventsDict setObject: eventsArray forKey: [NSDate dateWithDay:12 month:01 year:2014]];

我正在尝试遍历包含所有事件的 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"]];
        // NSDate *dateVariable = [dateformatter dateFromString:date];

        // Create events

        eventsArray = [[NSMutableArray alloc] init];
        aCKCalendarEvent = [[CKCalendarEvent alloc] init];
        aCKCalendarEvent.title = titleString;
        aCKCalendarEvent.date = [dateformatter dateFromString: date];
        [eventsArray addObject: aCKCalendarEvent];
        [_eventsDict setObject:eventsArray forKey:aCKCalendarEvent.date];
    }

问题是,如果我在同一天有多个事件,则只会显示最新的事件。我可以取出 eventsArray = [[NSMutableArray alloc] init]; 行,但是新事件不仅会在正确的日子与其他事件一起出现,而且还会在其他日子出现。所以我想我可以输入这样的东西来检查我是否需要该行,然后将事件添加到 eventsDict 但我得到 -[CKCalendarEvent isEqualToDate:]: unrecognized selector sent to instance 0xc6bb880 on if ([[eventsArray objectAtIndex:i]isEqualToDate:aCKCalendarEvent.date]):

BOOL dateExists;

        for (int i = 0; i < [eventsArray count]; i++)
        {
            if ([[eventsArray objectAtIndex:i]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];
        }

所以基本上,我需要一种方法来遍历 plist 并确定程序是否需要在每个新事件上初始化 eventsArray。



Best Answer-推荐答案


您正在将事件与日期进行比较。请参阅下面比较事件日期的代码。

if ([[(CKCalendarEvent *)[eventsArray objectAtIndex:i] date]isEqualToDate:aCKCalendarEvent.date])

关于ios - 使用 MBCalendarKit 创建事件的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20634933/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap