Using RestKit, use block to load object, when and how to cancel the request?

陌路散爱 提交于 2019-12-10 18:45:15

问题


[[RKObjectManager sharedManager] loadObjectsAtResourcePath:@"app/site_pattern" usingBlock:^(RKObjectLoader* loader) {
    [loader setObjectMapping:clientMappring];
    loader.delegate = self;
    shopLoader = loader;
}];

Above, I use the block function to load some data in my app, but when I pop this viewcontroller, I don't know when and how to cancel this request .

Any idea?

- (void)showSelectShop
{

    SelectShopViewController * selectShopViewController = [[SelectShopViewController alloc] initWithNibName:@"SelectShopViewController" bundle:nil];
    [self.navigationController pushViewController:selectShopViewController animated:YES];
}

More:

I try to cancel it in the viewDidUnload

- (void)viewDidUnload
{
    [super viewDidUnload];
    [shopLoader cancel];
}

But it didn't work. I still getting error.


回答1:


I solved this by adding

- (void)viewWillDisappear:(BOOL)animated
{
    [shopLoader cancel];
    shopLoader.delegate = nil;
    shopLoader = nil;
}

I still want to know if I don't want to cancel this request in viewWillDisappear, which function do those lines should be written in?



来源:https://stackoverflow.com/questions/11499281/using-restkit-use-block-to-load-object-when-and-how-to-cancel-the-request

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!