我正在試圖讓多個NSURLConnections並行(同步)運行,但是如果它沒有在主線程(代碼塊註釋如下)上運行,那麼URL連接不會運行t看起來可以工作(沒有任何NSURLConnection委託方法被觸發)。下面是代碼我有(一的NSOperation子類的實現文件):獲取多個NSURLConnections並行運行的問題
- (void)start
{
NSLog(@"DataRetriever.m start");
if ([self.DRDelegate respondsToSelector:@selector(dataRetrieverBeganExecuting:)])
[self.DRDelegate dataRetrieverBeganExecuting:identifier];
if ([self isCancelled]) {
[self finish];
} else {
/*
//If this block is not commented out NSURLConnection works, but not otherwise
if (![NSThread isMainThread])
{
[self performSelectorOnMainThread:@selector(start) withObject:nil waitUntilDone:NO];
return;
}*/
SJLog(@"operation for <%@> started.", _url);
[self willChangeValueForKey:@"isExecuting"];
_isExecuting = YES;
[self didChangeValueForKey:@"isExecuting"];
NSURLRequest * request = [NSURLRequest requestWithURL:_url];
_connection = [[NSURLConnection alloc] initWithRequest:request
delegate:self];
if (_connection == nil)
[self finish];
} //not cancelled
}//start
通過它跑了一個調試器,以及NSURLConnection的這種啓動方法沒有代表觸發結束後(我設置斷點那裏)。但在主線程上,它工作得很好。有什麼想法嗎?謝謝!
這樣做了,謝謝! – Stunner 2011-06-05 04:01:48