Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
323 views
in Technique[技术] by (71.8m points)

iphone - Modal View Controller Won't Start in Landscape Mode

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.

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.

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).

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.

Also, you don't need the setNeedsDisplay. That only effects the current views, not the modal you are presenting.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...