How do I set RKObjectManager's delegate to nil

2019-06-01 09:46发布

问题:

I want to set RKObjectManager's delegate to nil. But I can't find delegate property.

My request is:

[[RKObjectManager sharedManager] loadObjectsAtResourcePath:@"getData" 
  objectMapping:[[RKObjectManager sharedManager].mappingProvider 
                      objectMappingForKeyPath:@"clips"] delegate:self];

UPDATE: There is a crash in my app. I go to "Clips" and in the viewDidLoad send loadObjectsAtResourcePath. If I rapidly leave this screen I get crash at [RKResponse connection:didReceiveData:].

回答1:

The crash is caused by your 'delegate' object being dealloc'd. There is a simple solution to your problem - just cancel all pending request eg. in your viewDidUnload (or dealloc, it depends on your implementation) method.

- (void)viewDidUnload 
{
   ...
   [[[[RKObjectManager sharedManager] client] requestQueue] cancelRequestsWithDelegate:self];
   ...
}


标签: ios restkit