问题描述
我有一个基于导航的应用程序,它有一个详细视图(UIWebView),在UIToolbar的底部有操作按钮。我想在按下笔记按钮时添加笔记。当webview处于纵向模式时,一切正常。我按下备注按钮,模态视图打开正常并且效果很好。
I have a navigation based app that has a detail view (UIWebView) with action buttons across the bottom in a UIToolbar. I want to add 'notes' when the 'notes' button is pushed. Everything works fine when the webview is in portrait mode. I press the notes button, the modal view opens fine and works great.
当webview处于横向模式时会出现问题。如果我按下音符按钮,所有打开模态视图的代码都会被调用,但我得到的只是一个白色屏幕。一条评论:如果我以纵向打开模态视图然后旋转设备,它会精细旋转到横向模式。它只是在横向模式下无法正确打开。
The problem occurs when the webview is in landscape mode. If I press the notes button, all the code to open the modal view gets called but all I get is a white screen. One comment: If I open the modal view in portrait and then rotate the device, it rotates fine into landscape mode. It just won't open correctly in landscape mode.
我有另一个按钮,它会调出具有相同行为的邮件编辑器。这是我的UIWebViewController中的代码:
I have another button that brings up the mail composer which has the identical behavior. Here is the code in my UIWebViewController:
- (IBAction)addNotes:(id)sender
{
NotesViewController *notesViewController;
// create the view controller and set it as the root view of a new navigation
// controller
notesViewController = [[NotesViewController alloc] initWithPrimaryKey:self.record.primaryKey];
UINavigationController *newNavigationController =
[[UINavigationController alloc] initWithRootViewController:notesViewController];
// present the navigation controller modally
[self presentModalViewController:newNavigationController animated:YES];
[notesViewController release];
[self.view setNeedsDisplay]; // not sure if I need this! I was trying different things...
[self.devotionText setNeedsDisplay]; // ditto...
[newNavigationController release];
}
有什么想法吗?我尝试过各种不同的东西都无济于事。我只是得到一个没有导航栏的白色屏幕(虽然顶部有一个状态栏)。
Any ideas? I've tried all sorts of different things to no avail. I just get a white screen with no navigation bar (although there is a status bar at the top).
推荐答案
模态不要总是得到有关旋转的信息,他们从状态栏中获取信息,这并不总是正常工作。把它放在你的viewWillAppear中修复: [UIApplication sharedApplication] .statusBarOrientation = self.interfaceOrientation
而且,如果你想在模态中使用导航控制器,你需要创建一个。
Modals don't always get information about rotations, and they get their info from the status bar, which doesn't always work right. Put this in your viewWillAppear to fix: [UIApplication sharedApplication].statusBarOrientation = self.interfaceOrientation
And, if you want a navigation controller inside your modal, you need to create one.
此外,您不需要setNeedsDisplay。这只会影响当前的观看次数,而不会影响你所呈现的模式。
Also, you don't need the setNeedsDisplay. That only effects the current views, not the modal you are presenting.
这篇关于模态视图控制器无法在横向模式下启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!