IOS在viewdidload上添加了一个loadingview

时间:2012-08-24 17:40:18

标签: ios

我正在使用IOS 5的故事板。 由于图像处理繁重,我需要在viewdidload中加载弹出的加载视图。 它没有提出加载视图。我在不同的地方尝试过以下代码并且有效。只是不在viewdidload上。

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notify_action_finish:) name:@"StopLoadingView" object:nil];
loadingView =[tfbLoadingView loadingViewInView:[self.view.window.subviews objectAtIndex:0]];

提前致谢。

1 个答案:

答案 0 :(得分:1)

正如Eric在评论中所说,使用MBProgressHud加载视图..

将HUD添加为窗口的子视图。

    // Should be initialized with the windows frame so the HUD disables all user input by covering the entire screen
    HUD = [[MBProgressHUD alloc] initWithWindow:[UIApplication sharedApplication].keyWindow];

    // Add HUD to screen
    [self.view.window addSubview:HUD];

    // Register for HUD callbacks so we can remove it from the window at the right time
    HUD.delegate = self;

    HUD.labelText = NSLocalizedString(@"Loading Workbench", nil);
    HUD.detailsLabelText = NSLocalizedString(@"please wait", nil);

    // Show the HUD while the provided method executes in a new thread
    [HUD showWhileExecuting:@selector(loadWorkbench:) onTarget:self withObject:nil animated:YES];

添加以下委托方法:

- (void)hudWasHidden {
    // Remove HUD from screen 
    [HUD removeFromSuperview];

    // add here the code you may need

}

另外不要忘记在相应的头文件中添加MBProgressHUDDelegate