【问题标题】:presentModalViewController: doesn't returnpresentModalViewController:不返回
【发布时间】:2011-08-06 12:22:01
【问题描述】:

我发生了一件非常奇怪的事情。在我的应用程序委托中,我在 UITabBarController 上调用 presentModalViewController: 以显示实现 loadView 以显示图像的自定义类 (LoadingViewController)。当我在模拟器中针对 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];
}

【问题讨论】:

    标签: uiviewcontroller modalviewcontroller


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      当使用presentModalViewController. 时,UITabBarController 应该是 RootViewController 此外,IOS 3.2 还存在一个问题,当在 UITabBarController 的横向使用 presentModalViewController 时,如果它的所有视图控制器不覆盖 shouldAutorotateToInterfaceOrientation 并为横向返回是,它将导致presentModalViewController 挂起。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2012-01-16
        • 2011-01-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多