presentModalViewController:不返回

时间:2011-04-15 17:17:27

标签: uiviewcontroller modalviewcontroller

我发生了一件非常奇怪的事情。在我的app委托中,我正在调用presentModalViewController:在UITabBarController上显示一个自定义类(LoadingViewController),它实现loadView以显示图像。当我在模拟器中针对iOS 4.x设备(iPhone或iPad)进行测试时,它可以在所有方向上正常工作。但是,当我对3.2 iPad进行测试时,如果方向是纵向的,它只能正常工作。如果是横向,则presentModalViewController:方法不返回。调用loadView和viewDidLoad方法,但不会调用viewWillAppear:和viewDidAppear:方法。

有什么想法吗?

以下是LoadingViewController中的loadView代码:

- (void) loadView
{
    CGRect mainScreenBounds = [UIScreen mainScreen].bounds;

    UIImageView * loadingImageView = [[UIImageView alloc] initWithFrame: mainScreenBounds];

    loadingImageView.autoresizesSubviews = YES;
    loadingImageView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

    NSString * splashImageName = [self getSplashImageName: [UIDevice currentDevice].orientation];
    loadingImageView.image = [UIImage imageNamed: splashImageName];

    UIActivityIndicatorView * spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle: UIActivityIndicatorViewStyleWhiteLarge];
    CGRect spinnerFrame = spinner.frame;

    spinnerFrame.origin.x = (mainScreenBounds.size.width - spinnerFrame.size.width) / 2;
    spinnerFrame.origin.y = mainScreenBounds.size.height * 0.7f;

    spinner.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin
                             | UIViewAutoresizingFlexibleRightMargin
                             | UIViewAutoresizingFlexibleTopMargin
                             | UIViewAutoresizingFlexibleBottomMargin;
    spinner.frame = spinnerFrame;
    spinner.hidesWhenStopped = YES;

    [spinner startAnimating];

    [loadingImageView addSubview: spinner];

    // Add a label indicating we are working so the user knows what we are doing.
    UIColor * textColor = [UIColor blueColor];

    CGRect labelFrame = loadingImageView.frame;
    labelFrame.size.height = 40;
    labelFrame.origin.y = spinnerFrame.origin.y - 100;
    UILabel * workingLabel = [[UILabel alloc] initWithFrame: labelFrame];
    workingLabel.font             = [UIFont systemFontOfSize: 18.0];
    workingLabel.textColor        = textColor;
    workingLabel.backgroundColor  = [UIColor clearColor];
    workingLabel.textAlignment    = UITextAlignmentCenter;
    workingLabel.text             = NSLocalizedString(@"Searching for location...", @"Searching for location...");
    workingLabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin
                                  | UIViewAutoresizingFlexibleRightMargin
                                  | UIViewAutoresizingFlexibleTopMargin
                                  | UIViewAutoresizingFlexibleBottomMargin
                                  | UIViewAutoresizingFlexibleWidth
                                  | UIViewAutoresizingFlexibleHeight;

    [loadingImageView addSubview: workingLabel];
    [workingLabel release];

    [spinner release];

    self.view = loadingImageView;
    [loadingImageView release];
}

2 个答案:

答案 0 :(得分:0)

UITabBarController在使用presentModalViewController.时应该是RootViewController而且IOS 3.2存在一个问题,即如果所有它的viewcontrollers都没有覆盖presentModalViewController,那么当使用shouldAutorotateToInterfaceOrientation在UITabBarController中时对于横向返回yes,会导致presentModalViewController挂起。

答案 1 :(得分:0)

我们最终得到的解决方案是不要使用presentModalViewController,而是将LoadingViewController设置为根视图控制器。显然这不是一个完整的解决方案,但幸运的是,这对我们来说已经足够了。令人沮丧的是,当它在我们的应用程序的早期版本中运行良好时,不知道为什么presentModalViewController现在不起作用。我们已经做了一些破坏它的事情。