PresentModalViewController:不返回
我发生了一件非常奇怪的事情。在我的应用程序委托中,我在 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];
}
I have a really weird thing happening. In my app delegate, I'm calling presentModalViewController: on a UITabBarController to display a custom class (LoadingViewController) that implements loadView to display an image. When I test this in the simulator against an iOS 4.x device (iPhone or iPad), it works fine at all orientations. However, when I test against a 3.2 iPad, it only works fine if the orientation is portrait. If it is landscape, the presentModalViewController: method doesn't return. The loadView and viewDidLoad methods get called but the viewWillAppear: and viewDidAppear: methods don't get called.
Any ideas?
Here's the code for loadView in LoadingViewController:
- (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];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用
presentModalViewController
时,UITabBarController 应该是 RootViewController。 另外,IOS 3.2 还存在一个问题,即当在 UITabBarController 中横向使用presentModalViewController
时,如果所有视图控制器都没有覆盖>shouldAutorotateToInterfaceOrientation
并为横向返回 yes,这将导致presentModalViewController
挂起。UITabBarController should be the RootViewController when using
presentModalViewController.
Also there is an issue with IOS 3.2 that when usingpresentModalViewController
in landscape with the UITabBarController if all it's viewcontrollers don't overrideshouldAutorotateToInterfaceOrientation
and return yes for landscape, it will causepresentModalViewController
to hang.我们最终得到的解决方案是根本不使用presentModalViewController,而是将LoadingViewController 设置为根视图控制器。显然这不是一个完整的解决方案,但幸运的是它对我们来说已经足够好了。令人沮丧的是不知道为什么presentModalViewController现在不起作用,而它在我们应用程序的早期版本中运行良好。我们所做的一些事情破坏了它。
The solution we ended up with is to not use presentModalViewController at all but to set the LoadingViewController as the root view controller. Obviously this isn't a complete solution, but fortunately it was good enough for us. What's frustrating is not knowing why presentModalViewController doesn't work now when it worked fine in the previous version of our app. There's something we've done that has broken it.