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

相關問題