English 中文(简体)
页: 1 目的 B. 非工作环境
原标题:save: on a NSManagedObjectContext not working

在一名导航控制员中,我从1位控制器到2位控制器。

观点主计长 1 是一个表层视力控制器,配备一名履带式的ResultsController。 它收集特定情况的数据并显示数据。 接着,如果一行被开发,我会把控制器2收成。 在进行缝 the时,我利用我对控制器1的数据,确定了一位特定的国家感化控制器2的不动产。

现任控制者 2 我能够利用国家不动产数据显示数据,然后对数据进行修改,并节省费用: 当我回头看控制器1时,变化就反映了。 然而,如果我重新发射该信,则不会在任何观点控制人员中得到任何反映。

这就是我是如何节省开支的。

- (void)hiddenAttributeSwitchSlid:(UISwitch *)sender
{
    [self.workoutType.managedObjectContext performBlock:^{
        self.workoutType.workoutHiddenByDefault = [NSNumber numberWithBool:sender.isOn];
        NSError *error = nil;
        if (![self.workoutType.managedObjectContext save:&error]) {
            NSLog(@"There was an error in saving to context - %@", [error localizedDescription]);
        }
        else {
            NSLog(@"No error");
        }
    }];
}

工作范围 类型: 准备中确定的目标 ForSegue: before segueing to this view controller.

即便我不使用演奏:也不工作。

PS——我以前曾问过此类问题。 我通过这些建议而增长,但似乎没有任何工作。

最佳回答

你在模式中是否为这一特性设定了违约值?

核心数据有一套经确定的核心数据,在某些情形下(我并未将其全部缩小),有违约价值的属性在申请的背景中多次重新出现。

The way to test for this is to listen for the value being changed via KVO and log the changes then duplicate your test. If you see several changes then you know you are hitting that bug.

我所看到的唯一已知解决办法是消除违约价值。 如果需要违约数值,我将在<代码>NSManagedObject的子类别中添加该数值,然后更新验证方法,以加以核对。 我知道。

Update #2

你有多少背景?

你们是否利用父母子女的情况?

If so, are you saving the top most parent?

Update #3

Ok, a UIManagedDocument has two NSManagedObjectContext cases within its. 是否有理由使用<条码>管理文件? 您的申请中是否有不止一份文件? 如果你不这样做,我强烈建议你转向传统的核心数据组。

As for the saving issue directly, UIManagedDocument tries to save in the background when you exit the application. If can take a bit of time and, personally, is not very reliable. You can request a save on exit which will help to insure the save is speedy, but even then it can be unreliable.

你们如何退出申请?

你们是否在Xcode中杀害它?

您是不是背景,然后又恢复?

难道你会把它从SOS装置中去除?

您可以听听<条码>IDManagedDocument,以节省下来,然后打印一份标识,以便你能够看到实际节省到磁盘上。 这样做可能有助于帮助缩小目前和现在储蓄的准确幅度。

问题回答

我认为,你不要在环境中使用储蓄,该文件将自动节省费用。

There might be a data consistency error when the document is being saved. I propose to you not to use saving of the context by [self.workoutType.managedObjectContext save:&error] and use the following class inherited from UIManagedDocument which adds logging on auto-save:

记录:管理文件。

@interface LoggingManagedDocument : UIManagedDocument

@end

记录:

#import "LoggingManagedDocument.h"

@implementation LoggingManagedDocument

- (id)contentsForType:(NSString *)typeName error:(NSError *__autoreleasing *)outError
{
    NSLog(@"Auto-Saving Document");
    return [super contentsForType:typeName error:outError];
}

- (void)handleError:(NSError *)error userInteractionPermitted:(BOOL)userInteractionPermitted
{
    NSLog(@"error: %@ userInfo: %@", error, error.userInfo);
}

@end

这一类别应有助于你查明问题,因为你的数据没有保存。 在你改变属性和汽车后,申请才提出,等待15-30秒。

伐木的依据是:

摘自《协调管理文件》文件:

概念文件结构导致以下几个考虑:

You should typically use the standard UIDocument methods to save the document. If you save the child context directly, you only commit changes to the parent context and not to the document store. If you save the parent context directly, you sidestep other important operations that the document performs.

最容易的选择是使用一种无储蓄模式,即使用文件NS UndoManager。 我通常会这样做。

[self.workoutType.managedObjectContext.undoManager beginUndoGrouping];
before adding the changes and
[self.workoutType.managedObjectContext.undoManager endUndoGrouping];
after editing.

www.un.org/spanish/ecosoc 您需要拯救文件。

[document saveToURL:document.fileURL forSaveOperation:UIDocumentSaveForOverwriting completionHandler:NULL];




相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签