MBProgressView无法在iOS上等待UICollectionView

时间:2015-02-10 12:26:51

标签: ios uicollectionview mbprogresshud

MBProgressView无法在UICollectionView上运行以便在iOS中等待  它在其他视图控制器中工作正常,但是当我在uicollection视图控制器中使用时,它没有在屏幕上显示,请给我一个解决方案。

  

请查看以下链接

UICollectionVIEW Code

1 个答案:

答案 0 :(得分:0)

尝试添加到superview:

[MBProgressHUD showHUDAddedTo:self.collectionView.superview animated:YES];

<强>更新

好的,我已经检查了你的代码,它有点搞砸了。 这里发生了什么:

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0) {

       // You about to show HUD in your current VC views hierarchy
      MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.collectionView.superview animated:YES]; 
        hud.labelText = @"Loading...";
      // But immediately switching to another. Current VC will be off screen.
      // You will not see your HUD
      [self.tabBarController setSelectedIndex:1];
    }
...

然后:

- (void)viewDidDisappear:(BOOL)animated {
    NSLog(@"viewDidDisappear in Main Page");
    //  Looks like you want to hide your HUD here.
    // This code will be called right after [self.tabBarController setSelectedIndex:1],
    // cause current with gonna disappear.
    [MBProgressHUD hideHUDForView:self.view animated:YES];   
}

所以,如果你真的希望看到HUD(目前尚不清楚应该看多长时间):

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0) {
      MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.tabBarController.view];
     //  hide after 4 seconds
     [hud hide:YES afterDelay:4];

...