2012-03-01 14 views
0

私は情報をCMSにチェックする関数を呼び出すこの関数を持っています。 UIActivityIndi​​catorViewはチェックが完了するまでフリーズします。理由は分かりません。UIActivityIndi​​catorView freeze

EDIT:面白いことに、私は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

+0

それが凍って、そこからupdateFromInternetが起動されたといいました。 – Desmond

+0

バックグラウンドスレッドを参照しているコメントの意味は何ですか?メインスレッド以外から 'UIKit'オブジェクトを使用すべきではありません。ただし、スレッドコードは表示されていません。スレッドコードが他の場所にありますか、 'performSelector:withObject:afterDelay:をバックグラウンドスレッドとして参照していますか? – Jim

答えて

2

を使用しています。あなたの遅れに2.0とない2を追加 試み(私ははるかに小さい値使用するであろう - 0.3を言う)を

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

これはのあなたの問題が解決しない場合は、あなたが見て(またはポスト)する必要があり、余分なに関連するコードあなたのようなあなたのコードのようなもの:load.alpha = 1;とblackOverlay.hidden = 0;アクティビティインジケータに追加された要素であると仮定します。

+0

こんにちは、私のコメントを更新しました – Desmond

関連する問題