English 中文(简体)
NSFederateResults 主计长
原标题:NSFetchedResultsController s didChangeObject not called

我已经指定了NSF的收割者为财产...

@property (nonatomic, strong) NSFetchedResultsController *controller;

...并安排代表到我的班级。

self.controller.delegate = self;

然后,我落实了标题中提到的方法,并在其中设置了一个断点。

    - (void)controller:(NSFetchedResultsController *)controller 
                didChangeObject:(id)anObject 
                atIndexPath:(NSIndexPath *)indexPath 
                forChangeType:(NSFetchedResultsChangeType)type 
                newIndexPath:(NSIndexPath *)newIndexPath 
    {    

    => BREAKPOINT <=

    }

我为控制器创建了以下调取请求 :

  NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] initWithEntityName:@"Post"]; 
   // ... some sort ...
    self.controller = [[NSFetchedResultsController alloc]
                       initWithFetchRequest:fetchRequest
                       managedObjectContext:self.context
                       sectionNameKeyPath:nil
                       cacheName:@"cache"];

现在,我在同一个背景下将一些NSManagedObjects 储存在另一类“邮政”类型的“邮政”类型中,但“代码”中从未称它为“/坚挺” (我的断点在断点中)。

有谁知道哪里出了问题吗?

<强> 更新 # # 1 : 从服务器上获取一些文章并将其存储到上下文的类会使用GCD 自动执行 。

Update #2: I have tried it in another way due it does not work to use a context in a multithreaded environment. (Thanks to svena) Now the ServerConnection runs in an async block (using GCD) and performs a selector on the main thread. This selector method stores the posts in the database and SHOULD update the tableview. Basically, I thought that when I store something in this context the didChangeObject method should be called automatically? But it does not. :-/

I have added a short sequence diagram to illustrate my current status. sample sequence diagram Does anyone know why this does not work? Please be patient. I am new to CoreData and Objective-C. :)

最佳回答

更新 # 1 : 从服务器上获取一些文章并将其存储到上下文的类会使用GCD 自动执行 。

if this is the case, how are you creating your managed object context for the GCD block? Neither contexts or managed objects are thread safe and cannot be passed around between threads. Furthermore changes made to context on one thread is not automatically propagated to contexts on other threads. Prior to iOS5 that means listening to NSManagedObjectContextDidSaveNotification and merging it there by using mergeChangesFromContextDidSaveNotification: method for your NSFetchedResultsController instance to see it.

顺便提一下,

请在以下各点显示代码:

  1. Create your context
  2. Perform your block on the main thread to insert data
问题回答

暂无回答




相关问题
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, ...

热门标签