2013-04-07 85 views
0

我想在我的主線程上的tableview控制器上的子視圖中顯示一個微調。該視圖僅在偶爾顯示,並且通常在我的後臺線程完成後顯示。這裏是我的代碼:Uiactivityindicator沒有在子視圖中顯示

[self.view addSubview:spinnerView]; 
     [self.view bringSubviewToFront:spinnerView]; 
     self.spinnerView.layer.cornerRadius = 8; 
     self.spinnerView.center = CGPointMake(160, 150); 

     [spinner startAnimating]; 

     dispatch_queue_t downloadQueue = dispatch_queue_create("downloader", NULL); 
     dispatch_async(downloadQueue,^{ 
      dispatch_async(dispatch_get_main_queue(), ^{ 
       [NSThread sleepForTimeInterval:10]; 
       // Add recurring transactions if necessary 
       if (tran.recur.id != 0) { 
        [Utilities addRecurringTransactionsUpToCurrentMonthByTransaction:tran]; 
       } 

       [spinner stopAnimating]; 
       [self dismissViewControllerAnimated:YES completion:nil]; 
      }); 
     }); 
     dispatch_release(downloadQueue); 
    } 
} 
+0

不是一個Xcode的問題。 – 2013-04-07 12:05:17

回答

0

由於所有UI是在主線程運行,則必須調用performSelectorOnMainThread:withObject:waitUntilDone:如下圖所示:

[self.view addSubview:spinnerView]; 
    [self.view bringSubviewToFront:spinnerView]; 
    self.spinnerView.layer.cornerRadius = 8; 
    self.spinnerView.center = CGPointMake(160, 150); 

    [spinner performSelectorOnMainThread:@selector(startAnimating) withObject:nil waitUntilDone:NO]; 


    dispatch_queue_t downloadQueue = dispatch_queue_create("downloader", NULL); 
    dispatch_async(downloadQueue,^{ 
     dispatch_async(dispatch_get_main_queue(), ^{ 
      [NSThread sleepForTimeInterval:10]; 
      // Add recurring transactions if necessary 
      if (tran.recur.id != 0) { 
       [Utilities addRecurringTransactionsUpToCurrentMonthByTransaction:tran]; 
      } 

      [spinner performSelectorOnMainThread:@selector(stopAnimating) withObject:nil waitUntilDone:NO]; 

      [self dismissViewControllerAnimated:YES completion:nil]; 
     }); 
    }); 
    dispatch_release(downloadQueue); 
+0

此行爲與以前完全相同。微調工作目前在主線上。 – Carl 2013-04-07 19:23:55