1

我正在从网上下载数据,然后显示在UITableView上。因为我想要一个响应式用户界面,我使用后台下载GCD。所以,当数据下载时,有一个空的UITableView显示(这不是很漂亮)。此外还有一个UIActivtyIndicatorView(设置在IB中)旋转。iOS - 显示覆盖UITableView

我想要的是,而不是显示一个空的表来显示一个灰色的屏幕与UIActivityIndi​​catorView在它上面。

我到目前为止的代码是这样的:

dispatch_async(dispatch_get_global_queue(0, 0), ^{ 

    NSArray *downloadedCareerIds = [CareersParser idsFrom:@"web"]; 
    NSArray *diskCareerIds = [CareersParser idsFrom:@"disk"]; 

    BOOL equalIds = [downloadedCareerIds isEqualToArray:diskCareerIds]; 

    if (!equalIds) { 

     DLog(@"ids not equal"); 

     dispatch_async(dispatch_get_main_queue(), ^{ 
      /* Send UI updates back to the main thread. */ 

      // I think here would be a good idead to insert the gray view over the table 

      [loadingIndicator startAnimating]; 
      // Do GUI stuff on the main thread ... 
      [loadingIndicator stopAnimating]; 
      // Remove the gray view? 

     }); 
    } 
}); 

回答

0

只是做一个灰色的观点与UITableView中的界限,并将其添加为的tableView的子视图。完成加载后删除灰色视图。

+0

得到它的工作,但是在添加的子视图显示在桌面视图之前有一个小的延迟,所以你会看到半秒的空表,然后你会看到加载屏幕。 –

+0

你是否在你的问题中添加了灰色视图?如果是这样,并且希望灰色视图不被延迟,则应该在viewDidLoad中将灰色视图添加到tableview中。您可以将其保存到实例变量或属性(取决于您在做什么),然后像以前一样将其删除。 –