1

我有一个单独的类,我想处理来自 ASIHTTPRequest 的响应,所以我创建了一个类的实例,然后将它传递给我的请求。问题是我的委托类在请求完成之前被释放。

我正在使用ARC。如何确保为 didFinish/didFail 选择器保留委托?

-(void)getStuff
{
    NSURL *url = [NSURL URLWithString:@"http://example.com/json"];
    ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];

    UpdateFeedDelegate *updateFeedDelegate = [[UpdateFeedDelegate alloc] init];

    [request setDelegate:updateFeedDelegate];
    [request setDidFinishSelector:@selector(updateTestDone:)];
    [request setDidFailSelector:@selector(getSingleUpdateFeedBackgroundRequestFailed:)];

    [request startAsynchronous];
}

在示例中,选择器类按预期存在。我得到错误:

*** -[UpdateFeedDelegate respondsToSelector:]: message sent to deallocated instance 0x56efb50

*** NSInvocation: warning: object 0x56efb50 of class '_NSZombie_UpdateFeedDelegate' does not implement methodSignatureForSelector: -- trouble ahead

*** NSInvocation: warning: object 0x56efb50 of class '_NSZombie_UpdateFeedDelegate' does not implement doesNotRecognizeSelector: -- abort

4

1 回答 1

2

代表通常由weakassign财产持有。您需要保留 astrongretain对您的UpdateFeedDelegate某处的引用,以使其不会自动释放。通常,我将它保存在创建请求和委托的类中。

于 2012-08-03T15:26:21.273 回答