ModalViewController 不保存到核心数据?

发布于 2024-11-30 15:49:07 字数 1582 浏览 2 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

囚我心虐我身 2024-12-07 15:49:07

您的 save 方法是否被调用? knittingQueenViewController 被调用时是否非零? patternA 的值看起来正确吗?

Is your save method being called? Is knittingQueenViewController non-nil when it's called? Do the values of patternA look correct?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文