嗨我想創建一個NSOperaion隊列下載一堆PDF文件。但它不起作用。委託方法不會被調用NSURLConnection,因爲我把它們放在NSOperation隊列....任何替代或解決方案?與NSOperationqueu NSURLConnection問題
- (void) loadData {
NSOperationQueue *queue = [NSOperationQueue new];
NSInvocationOperation *operation;
for(int i=0;i<[self.pdfArray count];i++){
NSString *url = [NSString stringWithFormat:@"http://www.somelink.com/%@.pdf",[self.pdfArray objectAtIndex:i]];
operation = [[NSInvocationOperation alloc] initWithTarget:self
selector:@selector(loadDataWithOperation:)
object:url];
[queue addOperation:operation];
[operation release];
}
}
- (void) loadDataWithOperation:(NSString *) url{
// Create the request.
NSURLRequest *theRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:url]
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:60.0];
NSURLConnection *theDownload = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self startImmediately:YES];
}
您是否在您的loadDataWithOperation方法中放置了斷點或調試輸出以驗證它沒有被調用? – Greg 2010-10-04 20:11:47
是啊,這就是所謂...唯一的問題是,當我將它添加到nsoperationqueue它不起作用 – vivianaranha 2010-10-04 20:13:13
是否正確創建了下載? (你沒有從init返回nil。)你不應該,但是調用''[theDownload start]'有什麼區別? – 2010-10-04 20:36:34