2012-11-08 20 views
0

我已經成立了一個UILabel,後者從parse.com其內容。一切正常,直到我啓用飛行模式。在其中加載標籤認爲我會很長加載時間和控制檯給我的代碼:很長的加載與解析的NSString

2012-11-08 21:07:41.179 My App[5275:907] Warning: A long-running Parse operation is being executed on the main thread. 
Break on warnParseOperationOnMainThread() to debug. 
2012-11-08 21:07:41.231 My App[5275:907] Error: Error Domain=NSURLErrorDomain Code=-1009 "Es besteht anscheinend keine Verbindung zum Internet." UserInfo=0x1e5c2f00 {NSErrorFailingURLStringKey=https://api.parse.com/2/find, NSErrorFailingURLKey=https://api.parse.com/2/find, NSLocalizedDescription=Es besteht anscheinend keine Verbindung zum Internet., NSUnderlyingError=0x1e5c1d70 "Es besteht anscheinend keine Verbindung zum Internet."} (Code: 100, Version: 1.1.14) 
2012-11-08 21:07:41.232 My App[5275:907] Network connection failed. Making attempt 2 after sleeping for 1.287663 seconds. 
2012-11-08 21:07:42.582 My App[5275:907] Error: Error Domain=NSURLErrorDomain Code=-1009 "Es besteht anscheinend keine Verbindung zum Internet." UserInfo=0x1e5c6f00 {NSErrorFailingURLStringKey=https://api.parse.com/2/find, NSErrorFailingURLKey=https://api.parse.com/2/find, NSLocalizedDescription=Es besteht anscheinend keine Verbindung zum Internet., NSUnderlyingError=0x1e5c6f40 "Es besteht anscheinend keine Verbindung zum Internet."} (Code: 100, Version: 1.1.14) 
2012-11-08 21:07:42.583 My App[5275:907] Network connection failed. Making attempt 3 after sleeping for 2.575326 seconds. 
2012-11-08 21:07:45.215 My App[5275:907] Error: Error Domain=NSURLErrorDomain Code=-1009 "Es besteht anscheinend keine Verbindung zum Internet." UserInfo=0x1f88bd90 {NSErrorFailingURLStringKey=https://api.parse.com/2/find, NSErrorFailingURLKey=https://api.parse.com/2/find, NSLocalizedDescription=Es besteht anscheinend keine Verbindung zum Internet., NSUnderlyingError=0x1f88c840 "Es besteht anscheinend keine Verbindung zum Internet."} (Code: 100, Version: 1.1.14) 
2012-11-08 21:07:45.216 My App[5275:907] Network connection failed. Making attempt 4 after sleeping for 5.150652 seconds. 
2012-11-08 21:07:50.383 My App[5275:907] Error: Error Domain=NSURLErrorDomain Code=-1009 "Es besteht anscheinend keine Verbindung zum Internet." UserInfo=0x1f88c310 {NSErrorFailingURLStringKey=https://api.parse.com/2/find, NSErrorFailingURLKey=https://api.parse.com/2/find, NSLocalizedDescription=Es besteht anscheinend keine Verbindung zum Internet., NSUnderlyingError=0x1f88b4a0 "Es besteht anscheinend keine Verbindung zum Internet."} (Code: 100, Version: 1.1.14) 
2012-11-08 21:07:50.384 My App[5275:907] Network connection failed. Making attempt 5 after sleeping for 10.301305 seconds. 
2012-11-08 21:08:00.743 My App[5275:907] Error: Error Domain=NSURLErrorDomain Code=-1009 "Es besteht anscheinend keine Verbindung zum Internet." UserInfo=0x1e5c8160 {NSErrorFailingURLStringKey=https://api.parse.com/2/find, NSErrorFailingURLKey=https://api.parse.com/2/find, NSLocalizedDescription=Es besteht anscheinend keine Verbindung zum Internet., NSUnderlyingError=0x1f88e450 "Es besteht anscheinend keine Verbindung zum Internet."} (Code: 100, Version: 1.1.14) 

「ES besteht anscheinend keine Verbindung的Zum互聯網」意味着那裏有沒有互聯網連接。

有沒有辦法解決這個問題?

感謝

回答

1

不要做在主線程聯網 - 永遠:)

dispatch_async塊,僅設置標籤的主線程上的文字。

- (void)doLongOperation:(id)someParam withCompletionHandler:(void (^)(NSString *newLabelString))completionHandler { 
    dispatch_async(dispatch_get_global_queue(0,0), ^{ 
     NSString *labelString = /*do call to parse OR any other long running operation*/ 

     if (completionHandler) { 
      dispatch_async(dispatch_get_main_queue(), ^{ 
      completionHandler(labelString); 
     }); 
    }); 
} 

// now in your main app call it 
[self doLongOperation:nil /*we dont need anything here*/ withCompletionHandler:^(NSString *newLabelString) { 
    self.label.text = newLabelString; 
}]; 
+0

請什麼?對不起,我是一個新手。你能告訴我如何解決這個問題嗎? – MasterRazer

+0

對不起,是有點衝.. illl編輯我的答案 –

+0

哦,沒關係,但我發現別的東西來解決重複錯誤 – MasterRazer