我是一名新手程序员,我在这个问题上已经挣扎了两个星期。我正在使用cocoapods的JTCalendar。它旨在返回AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
NSManagedObjectContext *context = [appDelegate managedObjectContext];
NSManagedObject *savedate;
savedate = [NSEntityDescription insertNewObjectForEntityForName:@"AlarmData" inManagedObjectContext:context];
[savedate setValue:CT forKey:@"alarmDate"];
[context save:&error];
BOOL isSaved = [appDelegate.managedObjectContext save:&error];
NSLog(@"success!!!!, %@", savedate);
下的日期
它将在日历上显示为一个点以显示事件。要保存我的活动,请使用以下代码:
- (BOOL)calendarHaveEvent:(JTCalendar *)calendar date:(NSDate *)date
{
AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
NSManagedObjectContext *context = [appDelegate managedObjectContext];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"dd-MM-yyyy"];
NSString *textDate = [NSString stringWithFormat:@"%@",[dateFormatter stringFromDate:[NSDate date]]];
NSLog(@"Date %@",textDate);
NSDate *startDate = [dateFormatter dateFromString:@"31-12-1981"];
NSDate *endDate = [dateFormatter dateFromString:@"31-12-2999"];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(alarmDate >= %@) AND (date <= %@)", startDate, endDate];
NSFetchRequest *request = [[NSFetchRequest alloc] init];
[request setEntity:[NSEntityDescription entityForName:@"AlarmData" inManagedObjectContext:context]];
[request setPredicate:predicate];
NSError *error;
NSArray *matchingData = [context executeFetchRequest:request error:&error];
NSString *alarmDate = [ NSString stringWithFormat:@"dd-MM-yyyy"];
for (NSManagedObject *obj in matchingData) {
alarmDate = [obj valueForKey:@"alarmDate"];
return alarmDate;'
以及以下内容尝试获取日期并“返回”它:
// Top of file
App::uses('PaginatorHelper', 'View/Helper');
// Later in controller method
$paginatorHelper = new PaginatorHelper(new View(null));
$records = $this->paginate();
$count = $paginatorHelper->params()['count'];
可悲的是,结果看起来像这样,每个日期似乎都返回一个点下方:
https://drive.google.com/file/d/0Bw0Kf2Z9-yb8Zm5LWnZUUkRJRzQ/view?usp=sharing
我只想让我的单一日期归还,长期坚持下去。谢谢!
答案 0 :(得分:0)
for (NSManagedObject *obj in matchingData) {
alarmDate = [obj valueForKey:@"alarmDate"];
return alarmDate;'
无论您在方法参数中的日期是什么,总是返回第一个对象的alamrDate。使用您的参数检查日期,然后返回此日期是否有alerm。