Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 无法更新核心数据日期和布尔属性_Ios_Core Data - Fatal编程技术网

Ios 无法更新核心数据日期和布尔属性

Ios 无法更新核心数据日期和布尔属性,ios,core-data,Ios,Core Data,我还在学习如何在iOS上编程。在我正在进行的项目中,我试图更新核心数据中的信息,但我遇到了一个障碍。我无法更新日期和布尔属性。请帮忙!以下是我被绊倒的节目部分。随后是NSLog的输出 ItemUpdateViewController *updateView = segue.sourceViewController; NSDateFormatter* formattedDate = [[NSDateFormatter alloc] init]; formattedDate.dateFormat

我还在学习如何在iOS上编程。在我正在进行的项目中,我试图更新核心数据中的信息,但我遇到了一个障碍。我无法更新日期和布尔属性。请帮忙!以下是我被绊倒的节目部分。随后是NSLog的输出

ItemUpdateViewController *updateView = segue.sourceViewController;

NSDateFormatter* formattedDate = [[NSDateFormatter alloc] init];
formattedDate.dateFormat = @"dd/MM/yyyy";


// Update lastDone1 date

[self.monitorItem setValue:
    [formattedDate dateFromString:updateView.lastDone1TextField.text]
                            forKey:@"lastDone1"];

NSLog(@"lastDone1 text: %@", updateView.lastDone1TextField.text);
NSLog(@"lastDone1 from updateView: %@", 
    [formattedDate dateFromString:updateView.lastDone1TextField.text]);
NSLog(@"lastDone1 in self.monitorItem: %@",[self.monitorItem valueForKey:@"lastDone1"]);


// Update fixed boolean value

[self.monitorItem setValue:[NSNumber numberWithBool:YES] forKey:@"fixed"];

NSLog(@"fixed: %@",[self.monitorItem valueForKey:@"fixed"]);
输出: 2014-05-02 17:17:48.334 SGReceincyMonitor[805:70b]最新版本1文本:2014年5月2日 2014-05-02 17:17:48.336 SGReceincyMonitor[805:70b]最新更新查看:2014-05-01 16:00:00+0000 2014-05-02 17:17:48.336 SGReceincyMonitor[805:70b]self.monitorItem中的lastDone1:(空)

2014-05-02 17:17:48.336 SGReceincyMonitor[805:70b]固定:(空)

如图所示,核心数据返回两个(null)值

更新: 谢谢你!我补充了以下内容:

    SGRMAppDelegate *appDelegate = (SGRMAppDelegate *)[[UIApplication sharedApplication] delegate];
    [appDelegate saveContext];

然而,结果仍然是一样的。它都返回(null)值。

将值分配给核心数据对象后,保存数据库

[self.monitorItem setValue:
[formattedDate dateFromString:updateView.lastDone1TextField.text]
                        forKey:@"lastDone1"];
// need to save database here:
[APP_DELEGATE saveContext];

也许自我监控是零!请再次检查此变量谢谢您。是,self.monitorItem为空。由于我缺乏理解,设计中有一个基本原则。设法进行了重大的重新设计,现在一切正常。