gpt4 book ai didi

ios - 使用 MBCalendarKit 问题创建事件

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:44:31 24 4
gpt4 key购买 nike

我在我的应用程序中使用 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 0xc6bb880if ([[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。

最佳答案

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

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

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

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com