0

我正在构建一篇文章阅读应用程序。我正在使用AMSliderMenuhttps://github.com/SocialObjects-Software/AMSlideMenu) 库的菜单列表。如何在执行segue期间UIActivityIndi​​catorView?

我无法实施UIActivityIndicator,当我在表上单击单元格AMSlideMenu需要一定的时间,因为数据加载到花药以加载另一个视图。

我想给UIActivityIndicator当用户单击单元格UIActivityIndicator执行直到它打开另一个视图的时间。

这里是我的代码:

 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
     { 

      UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]; 
      spinner.center = CGPointMake(160, 240); 
      spinner.hidesWhenStopped = YES; 
      [self.view addSubview:spinner]; 
     [spinner startAnimating]; 
      dispatch_queue_t downloadQueue = dispatch_queue_create("downloader", NULL); 
      dispatch_async(downloadQueue, ^{ 
     [NSThread sleepForTimeInterval:10]; 
     dispatch_async(dispatch_get_main_queue(), ^{ 
     [spinner stopAnimating]; 

     }); 

    }); 
    NSString *segueIdentifier = [self.mainVC segueIdentifierForIndexPathInLeftMenu:indexPath]; 

     if (segueIdentifier && segueIdentifier.length > 0) 
     { 
     [self performSegueWithIdentifier:segueIdentifier sender:self]; 
      } 
     } 
+0

什么,当你按下一个细胞会发生什么?顺便说一句,考虑MBProgressHud https://github.com/jdg/MBProgressHUD。 – kelin 2014-09-04 13:16:56

+0

为什么不使用MBProgressHUD?其中最好的 – sreekanthk 2014-09-04 13:27:42

回答

2

在声明类级别范围UIActivityIndicatorView

UIActivityIndicatorView *spinner; 

主队列执行SEGUE:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]; 
    spinner.center = CGPointMake(160, 240); 
    spinner.hidesWhenStopped = YES; 
    [self.view addSubview:spinner]; 
    [spinner startAnimating]; 
    dispatch_queue_t downloadQueue = dispatch_queue_create("downloader", NULL); 
    dispatch_async(downloadQueue, ^{ 
    [NSThread sleepForTimeInterval:10]; 
     dispatch_async(dispatch_get_main_queue(), ^{ 
      NSString *segueIdentifier = [self.mainVC segueIdentifierForIndexPathInLeftMenu:indexPath]; 
      if (segueIdentifier && segueIdentifier.length > 0){ 
       [self performSegueWithIdentifier:segueIdentifier sender:self]; 
      }else{ 
       [spinner stopAnimating]; 
      } 
     }); 
    }); 
} 

做SEGUE时停止微调:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender 
{ 
    [spinner stopAnimating]; 
} 
+0

非常感谢!美达,它的工作很好。 – Daljeet 2014-09-04 13:56:53

相关问题