는 일이 내가 가지고 (컴파일러가 코드를 실행하지만 아무것도하지 않음) 실행되지 않습니다 일부 코드, ... 여기 코드가 NSURLSessionDelegate
및 [NSOperationQueue mainQueue] addOperationWithBlock
NSOperationQueue가 addOperationWithBlock과 함께 제출 된 블록을 실행하지 않는 이유는 무엇입니까?
@interface tablaPosViewController : UIViewController <NSURLSessionDelegate>
@end
@implementation tablaPosViewController()
- (void)viewDidLoad
{
//some code to set the view, labels and stuff
[self downloadTheHTMLdata] // this code download some data from WWW
}
- (void)downloadTheHMTLdata
{
//some code to set the session using an object
[object.downloadTask resume]; //Begins the download
}
- (void)toFixTablaPosiciones
{
//some code to do with the downloaded data from WWW (and HTML sheet)
//here, parse the HTML Sheet, and put some data into an Arrays, and another public vars
//call another method
[self PutTheDataInLabel];
}
- (void)PutTheDataInLabel
{
//some code to put all the data in every label
//take the public vars that was set in the previous method, and do some code with it
//and put the info into the labels
//call another method
[self MoreStuff];
}
- (void)MoreStuff
{
//some code..
}
-(void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask didFinishDownloadingToURL:(NSURL *)location
{
//When the download finish this method fire up!
//this is to copy file from tmp folder to Docs folder
if ([fileManager fileExistsAtPath:[destinationURL path]])
{
[fileManager removeItemAtURL:destinationURL error:nil];
}
BOOL success = [fileManager copyItemAtURL:location //TMP download folder
toURL:destinationURL //Documents folder
error:&error];
//HERES COMES THE TROUBLE!!!
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
[self toFixTablaPosiciones]; //Call this method, that has other method calls!
}];
}
@end
UPDATE를 사용하여 ...입니다
대기열이 다른 코드 풋 방법 ...
-(void)URLSessionDidFinishEventsForBackgroundURLSession:(NSURLSession *)session{
AppDelegate *appDelegate = [UIApplication sharedApplication].delegate;
[self.session getTasksWithCompletionHandler:^(NSArray *dataTasks, NSArray *uploadTasks, NSArray *downloadTasks) {
if ([downloadTasks count] == 0) {
if (appDelegate.backgroundTransferCompletionHandler != nil) {
void(^completionHandler)() = appDelegate.backgroundTransferCompletionHandler;
appDelegate.backgroundTransferCompletionHandler = nil;
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
completionHandler();
}];
}
}
}];
}
다운로드 파일이 끝날 때 문제는이 -(void)URLSession:(NSURLSession *)session downloadTask:...
메서드를 호출하고 내가 [[NSOperationQueue mainQueue] addOperationWithBlock:^{...
실행 전자 기다릴 뭐든지 ... [self toFixTablaPosiciones]
의 anythig는 실행되지 않습니다 !! !!
나는 코드를 한 단계 씩 실행했다. 컴파일러가 모든 코드를 메소드를 통해 실행하는 방법을 본다.하지만 뷰가 업데이트되지 않고 실행되지는 않지만 단순히 아무것도하지 않는다. 표시기를 멈추고 싶지만 lablels는 dummie 데이터로 계속 남아 있고 활동 표시기는 절대로 멈추지 않으며 절대로 사라지지 않습니다. 이전보기에서 비슷한 파일을 사용하여 다른 파일을 다운로드하고 매우 빠르게 다운로드합니다. 이 뷰/클래스에 가서 다운로드를 수행하려고하면이게 문제가됩니다. ...
어떤 신체가 나에게 도움이 될 수 있으면 어떤 조언을 나에게 보낼 수 있습니다. 감사!
주 스레드에서 UI를 업데이트하고 있습니까? – Joel
예, 이것은 뷰와 함께 작동하는 완전한 클래스이며 viewDidLoad를 사용하여 dummie 데이터가있는 뷰를 설정하고 다운로드 완료 후에 메인 스레드 (사용자가보고있는 내용)의 올바른 데이터로 모든 레이블을 업데이트합니다 –
주 작업 대기열은 직렬 대기열입니다. 한 번에 하나의 작업 만 실행할 수 있습니다. 이 큐에 작업을 추가하는 유일한 장소입니까? 또는 다른 작업을 추가합니까? 그들 중 누구라도 오랜 시간 동안 실행되거나 완료하기 위해 다른 것을 기다리는 것을 차단합니까? –