2011-07-19 4 views
0

サーバからリストを取得したいのですが時間がかかっていますので、その時点で進行状況を表示しています。私の問題は、進行状況インジケーターが表示されていて、表示されないことがあります。私が使用したコードは、誰も私を助けてください問題i iphone sdkに進行状況インジケータが表示されていますか?

-(void)viewWillAppear:(BOOL)animated 

{ 
    [self loadprogressIndicator]; 
} 

-(void)loadprogressIndicator 
{ 
    MessengerAppDelegate* appDelegate = (MessengerAppDelegate*) [ [UIApplication sharedApplication] delegate]; 
    [appDelegate showWaitingView]; 

    [NSThread detachNewThreadSelector:@selector(statusIndicatorForRefresh) toTarget:self withObject:nil]; 
} 

-(void)statusIndicatorForRefresh 
{ 
    NSAutoreleasePool* pool=[[NSAutoreleasePool alloc]init]; 
    [UIApplication sharedApplication].networkActivityIndicatorVisible = YES; 
    [self performSelectorOnMainThread:@selector(loadList) withObject:nil waitUntilDone:NO]; 
    [NSThread exit]; 
    [pool release]; 
} 

-(void)loadList 
{ 
    MessengerAppDelegate* appDelegate = (MessengerAppDelegate*) [ [UIApplication sharedApplication] delegate]; 
    customerList = [appDelegate getCustomersArray]; 
    [theTableView reloadData]; 
    [appDelegate removeWaitingView]; 
} 

And in appdelegate.m I implemeted these two methods 

- (void)showWaitingView 
{ 
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 
    CGRect frame = CGRectMake(90, 190, 32, 32); 
    UIActivityIndicatorView* progressInd = [[UIActivityIndicatorView alloc] initWithFrame:frame]; 
    [progressInd startAnimating]; 
    progressInd.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge; 
    frame = CGRectMake(130, 193, 140, 30); 
    UILabel *waitingLable = [[UILabel alloc] initWithFrame:frame]; 
    waitingLable.text = @"Processing..."; 
    waitingLable.textColor = [UIColor whiteColor]; 
    waitingLable.font = [UIFont systemFontOfSize:20]; 
    waitingLable.backgroundColor = [UIColor clearColor]; 
    frame = [[UIScreen mainScreen] applicationFrame]; 
    UIView *theView = [[UIView alloc] initWithFrame:frame]; 
    theView.backgroundColor = [UIColor blackColor]; 
    theView.alpha = 0.7; 
    theView.tag = 999; 
    [theView addSubview:progressInd]; 
    [theView addSubview:waitingLable]; 
    [progressInd release]; 
    [waitingLable release]; 
    [window addSubview:[theView autorelease]]; 
    [window bringSubviewToFront:theView]; 
    [pool drain]; 
} 

- (void)removeWaitingView 
{ 
    UIView *v = [window viewWithTag:999]; 
    if(v) [v removeFromSuperview]; 

}

です。ハッピーコーディング..

ありがとうございます。

Praveena ..

答えて

0

メインスレッドですべての作業を行っています。 UIスレッドをブロックするため、アプリがブロックされているように見えます。

NSThreadを起動するのは、メインスレッド上でメソッドを呼び出しても完了するのを待っていない場合、どうすればいいですか?あなたはマルチスレッドを何もしていません。

あなたのアプリがこのん

:メインスレッドで

  • ビューを待っ

    • がショー1つの実行ループサイクル
    ビューを待ってデータ処理
  • 非表示をしますか

    あなたのデータ処理以降あなたはすべてのブロックをメインスレッドにしています。セカンダリスレッドで処理を行い、メインスレッドをUI処理のために残す必要があります。

  • +0

    どうすればいいか教えてもらえますか? – praveena

    +0

    iPhoneをプログラミングしてマルチスレッドを使う方法を学ぶのは、stackoverflow質問の対象外です。また、UIViewを直接ウィンドウに追加します。アプリがデバイスローテーションをサポートしている場合は、あらゆる種類の問題に注意してください。 –

    関連する問題