2012-03-01 144 views
0

我有這個函數調用函數來檢查CMS的信息。但UIActivityIndi​​catorView凍結直到檢查完成。不知道爲什麼。UIActivityIndi​​catorView freeze

編輯:有趣的事情之一,我註釋了performselector。 UIActivityIndi​​catorView仍然凍結。直到我拍了拍我的背按鈕,然後它開始打轉....

我使用的故事板,iOS 5的

-(void)showLoading 
{ 
    [activity startAnimating]; 
    //loading is a label to show "File Loading" 
    loading.alpha =1; 
    //is a label to show a 0.3 alpha of the label 
    blackOverlay.hidden =0; 
    [self performSelector:@selector(updateFromInternet:) withObject:@"a" afterDelay:2]; 

    //[self updateFromInternet:@"a"]; 
} 

-(void)updateFromInternet:(NSString *)urlStr 

{ 

    NSString *URLString = @"http://sites.google.com/site/iphonesdktutorials/xml/Books.xml"; 
    NSURL *updateDataURL = [NSURL URLWithString:URLString];  

    NSMutableURLRequest *WPXMLFetchRequest = [NSMutableURLRequest requestWithURL:updateDataURL]; 

    self.receivedData = [NSMutableData data]; 
    self.updateConnection = [NSURLConnection connectionWithRequest:WPXMLFetchRequest delegate:self]; 

    NSLog(@"Checking update at : %@", updateDataURL); 

    //[self.updateConnection cancel]; 
} 



-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data 
{ 
    ////NSlog(@"Receiving data"); 
    [self.receivedData appendData:data]; 
} 

-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error 
{ 
    ////NSlog(@"Failed to receive data"); 
    self.receivedData = nil; 
} 

-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response 
{ 
    ////NSlog(@"Received response from data"); 
    [self.receivedData setLength:0]; 
} 

- (void)connectionDidFinishLoading:(NSURLConnection *)connection { 

    NSString *data=[[NSString alloc]initWithData:self.receivedData encoding:NSUTF8StringEncoding]; 
    NSLog(@"data %@",data); 

    NSError *parseError = nil; 
    //NSDictionary *xmlDict = [XMLReader dictionaryForXMLData:self.receivedData error:&parseError]; 
    self.receivedDict = [XMLReader dictionaryForXMLData:self.receivedData error:&parseError]; 

    [self showDataOnScrollView]; 
} 
+0

「活動」是否開始然後凍結或只是保持凍結? – tipycalFlow 2012-03-01 12:34:18

+0

它的理由凍結在那裏,在updateFromInternet被稱爲它開始 – Desmond 2012-03-01 12:37:13

+0

評論引用後臺線程的含義是什麼?您不應該使用主線程以外的任何其他UIKit對象。但是你沒有顯示任何線程代碼。線程代碼是否在其他地方,或者你是否指向'performSelector:withObject:afterDelay:作爲後臺線程(它不是)? – Jim 2012-03-01 12:45:14

回答

2

你應該推遲「重」功能的一下,讓活動指示燈火。 嘗試添加2.0而不是2到你的延遲(我會用一個更小的值 - 說0.3)

[self performSelector:@selector(updateFromInternet:) withObject:@"a" afterDelay:0.3]; 

如果這不能解決你的問題,你應該看看(或郵寄)相關的額外代碼你的代碼中有這樣的內容:loading.alpha = 1;和blackOverlay.hidden = 0;我認爲這些元素是添加到活動指標中的元素

+0

hi shishi,更新了我的評論 – Desmond 2012-03-01 13:06:51

相關問題