我在我的 iOS 应用程序中使用 ASIHTTPRequest。我这样做: .h
@interface MyClassr
ASIFormDataRequest *currentRequest;
}
NSURL *url = [NSURL URLWithString:requestUrl];
currentRequest = [ASIFormDataRequest requestWithURL:url];
currentRequest.requestMethod=@"GET";
currentRequest.delegate =self;
[currentRequest setCompletionBlock:^{
listesRestaurants = [XMLParser parseRestaurantResponse:[currentRequest responseData]];
NSLog(@"%@",[currentRequest responseString]);
if (apDelegate.modeGeoloc) {
[map removeAnnotations:map.annotations];
[self addAnnotation];
[self calculDistance];
}
我在行中有一个警告:[currentRequest setCompletionBlock:^
//Block will be retained by an object strongly retained by the captured object
//在此 block 中强烈捕获'self'很可能导致保留循环
请问我该如何纠正这个警告?
最佳答案
您需要创建对自身的弱引用:
__weak MyClassr* blockSelf = self;
然后在您的 block 中使用该引用:
[blockSelf addAnnotation];
[blockSelf caculDistance];
等等
关于objective-c - 警告 ASIHttpRequest,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9909830/