简体   繁体   English

在NSObject类中未收到NSFetchedResultscontroller回调

[英]NSFetchedResultscontroller Callbacks not received in NSObject Class

I have a class, 我有课

@interface OnlineDataModel : TTModel < NSFetchedResultsControllerDelegate > { ... @interface OnlineDataModel:TTModel <NSFetchedResultsControllerDelegate> {...

Where TTModel is, TTModel在哪里

@interface TTModel : NSObject < TTModel > { ... @interface TTModel:NSObject <TTModel> {...

OnlineDataModel class is Singleton, so its object never expires. OnlineDataModel类为Singleton,因此其对象永不过期。 I am performing the Fetch operation within this class and setting the delegate of the fetchedResultsController by self. 我正在此类中执行Fetch操作,并自行设置fetchedResultsController的委托。 Now i am changing the objects fetched after constanct delay to just check that it gives the call backs, objects are changed and changes are reflected to the database as well, But OnlineDataModel class is not receiving the Call Backs so that my UI can get updated. 现在,我正在更改经过长时间延迟后获取的对象,以仅检查它是否提供了回调,对象也已更改并且更改也反映到了数据库中,但是OnlineDataModel类未接收到回调,因此我的UI可以更新。

i am badly stuck in it , so any help will highly be appreciated. 我严重地陷在其中,因此我们将不胜感激。

Thanks in advance :) 提前致谢 :)

How/Where do you set the delegate? 您如何/在哪里设置代表? If you set the delegate to self in a class method (has a + infront of its name instead of a - ... like + (void) doSomething) the delegate is set to the class object and not the instance object. 如果您在类方法中将委托设置为self(其名称前面带有+而不是-...,例如+(void)doSomething),则该委托将设置为类对象,而不是实例对象。

for me this works: 对我来说这有效:

@implementation MyViewController

...

- (NSFetchedResultsController *) fetchedResultsController
{
...
    [fetchedResultsController setDelegate: self];
...
    return fetchedResultsController;
}

- (void)controllerDidChangeContent:(NSFetchedResultsController *)controller
{
    NSLog(@"data changed");
}

...

@end

Please post your controller-creation code :) 请发布您的控制器创建代码:)

Before i post the code, i have a doubt on some thing, see the following code first 在发布代码之前,我对某些事情有疑问,请首先参阅以下代码

Book *book = [[[[CDBManager sharedManager] fetchedResultsController] fetchedObjects] objectAtIndex:index];
[book setTitle:@"New Title"];
[[[DatabaseContext sharedObject] managedObjectContext] save:nil];

Is this code causes any event to be fired from FetchedResultController, i guess fetchedObjects return copy of the Array. 此代码是否会导致从FetchedResultController触发任何事件,我想fetchedObjects返回Array的副本。 if its a copy, than definetly no call back will ever be received. 如果是副本,则绝对不会收到任何回拨。 But its the array of live objects than there is some thing in my code.. What you say on this ? 但是它的活动对象数组比我的代码中有一些东西。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM