-1

UIAlertView Loading インジケーターの次のコードがありますが、これは機能せず、私に与えてくれます

- (void) launchActivity
{
 //some logic...
[NSThread detachNewThreadSelector:@selector(updateFilterProgress) toTarget:self withObject:nil];
}
- (void) updateFilterProgress {
 if ((internetStatus != ReachableViaWiFi) && (internetStatus != ReachableViaWWAN))
{
    UIAlertView *myAlert = [[[UIAlertView alloc] initWithTitle:@"No Internet Connectivity" message:@"This app require an internet connection via WiFi or cellular network to work." delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil] autorelease];
    [myAlert show];
}
else{
    UIAlertView *alertMe = [[[UIAlertView alloc] initWithTitle:@"Loading..." message:nil delegate:nil cancelButtonTitle:nil otherButtonTitles: nil] autorelease] ;


  //tried this way by placing below line....no result   
  [alertMe performSelectorOnMainThread:@selector(show) withObject:nil waitUntilDone:YES];
    //[alertMe show];

 //some logic...
}

更新: メイン スレッドで、Web サービスを呼び出してデータを読み込んでいます。したがって、UIAlertView の読み込み用に別のスレッドを用意しましたが、iOS 4,5 で動作していました。しかし、iOS 6 でクラッシュします。AlerView をメイン スレッドに配置している場合、ロード中に何も表示されませんが、データがロードされた後、AlertView にはロード インジケータが数秒間表示されます。なにか提案を...

4

3 に答える 3

0

これを試して

- (void) launchActivity
{
 //some logic...
[NSThread detachNewThreadSelector:@selector(updateFilterProgress) toTarget:self withObject:nil];
}
- (void) updateFilterProgress {
 if ((internetStatus != ReachableViaWiFi) && (internetStatus != ReachableViaWWAN))
{
    [self performSelectorOnMainThread: @selector(showAlertForNoNetConnect)];
}
else{
    [self performSelectorOnMainThread: @selector(showAlertForLoading)];
 //some logic...
}

- (void) showAlertForNoNetConnect
{
    UIAlertView *myAlert = [[[UIAlertView alloc] initWithTitle:@"No Internet Connectivity" message:@"This app require an internet connection via WiFi or cellular network to work." delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil] autorelease];
    [myAlert show];

}
- (void) showAlertForLoading
{
    UIAlertView *alertMe = [[[UIAlertView alloc] initWithTitle:@"Loading..." message:nil delegate:nil cancelButtonTitle:nil otherButtonTitles: nil] autorelease] ;
    [alertMe show];

}

メイン スレッドですべての UIKit 要素を呼び出す必要があります。それが問題です。お役に立てれば。ハッピーコーディング。:)

于 2012-11-05T12:33:31.610 に答える