ModalViewController 不保存到核心数据?
iPad 应用程序粉丝:
我有一个模态视图控制器,旨在通过点击按钮弹出,以便用户可以添加注释或更改数据输入。当数据库发生更改时,需要刷新主窗口中的表。该数据库包含一种高级书签。我可以根据用户浏览的位置创建和删除数据库条目 - 没问题:我收到控制台报告“saveContext KQVC line 203”,并且条目很快添加到表中。
模态视图控制器甚至会弹出(点击每个单元格中的蓝色 (>) 详细信息图标)现有记录的填充数据。然而,模态视图控制器上的保存按钮只是不保存。 (删除功能很好用)。这是我的 modalviewcontroller 保存按钮的代码:
#import "PatternViewController.h"
#import "KnittingQueenViewController.h"
@implementation PatternViewController
@dynamic patternName, patternNotes, patternUrl, dateAdded;
@synthesize patternA, patternView, knittingQueenViewController;
-(IBAction)save {
[patternA setValue:patternName.text forKey:@"patternName"];
[patternA setValue:patternUrl.text forKey:@"patternUrl"];
[patternA setValue:patternNotes.text forKey:@"patternNotes"];
dateAdded = [NSDate date];
[patternA setValue:dateAdded forKey:@"dateAdded"];
[patternA setValue:patternLabel.text forKey:@"patternLabel"];
[patternA setValue:pngPath forKey:@"patternPhoto"];
[knittingQueenViewController saveContext];
[self dismissModalViewControllerAnimated:YES];
}
以及 knittingqueenviewcontroller 中的 saveContext 方法:
- (void)saveContext {
NSManagedObjectContext *context = [self.fetchedResultsController managedObjectContext];
NSError *error = nil;
if (![context save:&error]) {
// error code goes in here
}
NSLog(@"saveContext KQVC line 203");
[self refreshPatternsTable];
}
我没有收到任何错误,但也没有保存数据。我的问题:为什么不从 modalviewcontroller 调用方法 saveContext ?您能提供的任何建议将不胜感激。
iPad app fans:
I've got a modalviewcontroller designed to popup on a button tap so users can add notes or change data inputs. A table in the main window needs to be refreshed as changes to the database are made. The database incorporates a kind of advanced bookmark. I can create and delete database entries based on where users browse - no problem: I get the console report "saveContext KQVC line 203" and entries are quickly added into the table.
The modalviewcontroller even pops (on tapping the blue (>) detail icon also in each cell) with populated data of existing records. However the save button on the modalviewcontroller just doesn't save. (the delete function works great). Here's my code for the modalviewcontroller save button:
#import "PatternViewController.h"
#import "KnittingQueenViewController.h"
@implementation PatternViewController
@dynamic patternName, patternNotes, patternUrl, dateAdded;
@synthesize patternA, patternView, knittingQueenViewController;
-(IBAction)save {
[patternA setValue:patternName.text forKey:@"patternName"];
[patternA setValue:patternUrl.text forKey:@"patternUrl"];
[patternA setValue:patternNotes.text forKey:@"patternNotes"];
dateAdded = [NSDate date];
[patternA setValue:dateAdded forKey:@"dateAdded"];
[patternA setValue:patternLabel.text forKey:@"patternLabel"];
[patternA setValue:pngPath forKey:@"patternPhoto"];
[knittingQueenViewController saveContext];
[self dismissModalViewControllerAnimated:YES];
}
and the saveContext method in the knittingqueenviewcontroller:
- (void)saveContext {
NSManagedObjectContext *context = [self.fetchedResultsController managedObjectContext];
NSError *error = nil;
if (![context save:&error]) {
// error code goes in here
}
NSLog(@"saveContext KQVC line 203");
[self refreshPatternsTable];
}
I get no errors, but no saved data either. My question: why isn't the method saveContext being called from the modalviewcontroller? Any suggestions you can offer would be most appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的
save
方法是否被调用? knittingQueenViewController 被调用时是否非零?patternA
的值看起来正确吗?Is your
save
method being called? IsknittingQueenViewController
non-nil when it's called? Do the values ofpatternA
look correct?