我有很多正在发送请求的类,最后都是SplitViewController
。在SplitUIviewclass
中,我必须长时间轮询并在表格视图中写入数据。长轮询在后台线程中完成,所以我已经在应用程序委托中声明了一个变量,但是当涉及到它时,它是nil
。而问题是每当我试图通过appdelegate
访问NSMutablearray
时,它的到来nil
和数组正在被释放。我对长轮询代码如何在每个类中保留弧中的变量
- (void) longPoll {
@autoreleasePool
{
//compose the request
NSError* error = nil;
NSURLResponse* response = nil;
NSURL* requestUrl = [NSURL URLWithString:@"http://www.example.com/pollUrl"];
NSURLRequest* request = [NSURLRequest requestWithURL:requestUrl];
//send the request (will block until a response comes back)
NSData* responseData = [NSURLConnection sendSynchronousRequest:request
returningResponse:&response error:&error];
//pass the response on to the handler (can also check for errors here, if you want)
[self performSelectorOnMainThread:@selector(dataReceived:)
withObject:responseData waitUntilDone:YES];
}
//send the next poll request
[self performSelectorInBackground:@selector(longPoll) withObject: nil];
}
- (void) startPoll {
[self performSelectorInBackground:@selector(longPoll) withObject: nil];
}
- (void) dataReceived: (NSData*) theData {
//i write data received here to app delegate table
}
如果我把从数据我SPLITVIEW类中的任何其他方法来接收,我失去了控制,我也不能打印接收到的数据或变量我的应用程序委托值被释放,我无法从这里调用重载表或任何其他方法。
设置你的财产强/保留 – codercat
你可以在dataRecieved:方法中打印“theData”?这是对的吗?如果是这样你需要发布更多的代码。 – Ievgenii
我可以在dataRecieved中打印theData,并确定给我一些时间生病d完成问题 – BackStabber