views:

202

answers:

4

Hi all.

I'm at a loss...

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

I'm desperate! I'd love some feedback!!

Thanks so much!

Beth

A: 

You don't need a new Navigation Controller.

- (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];

 [self.navigationController pushViewController: notesViewController animated: YES];
 [notesViewController release];
}
Stephen Furlani
I removed the navigation controller and am still getting the same behavior. Thanks so much for replying. Any other ideas?
Glasswing
+2  A: 

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.

MishieMoo
Thanks for replying so quickly! I tried putting the statusBarOrientation code into my NotesViewController viewWillAppear and I still get the same behavior! I also removed the new navigation controller and still don't get anything...just the white screen. Any other suggestions?
Glasswing
Can you post some code for the initWithPrimaryKey function? Posting some code on that file will help immensely!
MishieMoo
The init function is simple...the xib file is just a UIView with a UITextView under it.
Glasswing
Oops...let me try that again...see the next answer....
Glasswing
Actually the nib is just a UIView and I create the UITextView programmatically. (I've tried it both ways...)
Glasswing
Have you tried logging your subviews? Add in a NSLog in viewWillAppear that prints out the subviews (self.view.subviews) to make sure your textfields are actually getting created. Are they? Have you stepped through this in the debugger?
MishieMoo
Yep. The textview is getting created. I have set the background view to blue and the textview to red (to debug). I even commented out creating of the textview subview. When I open the notes view (the blue one) in landscape, it still shows a white screen (not blue). I'm thinking that maybe it has to do with frames/layouts/layers? I'm completely stumped...
Glasswing
A: 

The init function for the NotesViewController is as follows:

- (id)initWithPrimaryKey:(NSInteger)key {
    // initialize the view, passing in the primary key so that we can 
    // load any existing notes
    if (self = [super initWithNibName:@"NotesViewController" bundle:nil]) {

    }
    self.primaryKey = key;

    return self;
}

Again, it works just as expected when starting in portrait and when rotating TO landscape while displaying the text...

viewDidLoad just calls setupTextView which looks like:

- (void)setupTextView
{
    self.textView = [[[UITextView alloc] initWithFrame:self.view.frame] autorelease];

    self.view.backgroundColor = [UIColor blueColor]; // for debugging

    // set up a text view for the user to enter notes into
    self.textView.textColor = [UIColor blackColor];
    self.textView.font = [UIFont fontWithName:@"Arial" size:18];
    self.textView.delegate = self;
    self.textView.backgroundColor = [UIColor redColor]; // for debugging

    // if there are previous notes, edit them else add new ones
    [self loadNotesIntoTextView];
    self.textView.returnKeyType = UIReturnKeyDefault;
    self.textView.keyboardType = UIKeyboardTypeDefault; // use the default type input method (entire keyboard)
    self.textView.scrollEnabled = YES;

    // this will cause automatic vertical resize when the table is resized
    self.textView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
    self.navigationItem.title = @"Notes";

    UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStyleBordered target:self action:@selector(backAction:)];
    self.navigationItem.leftBarButtonItem = backButton;
    [backButton release];
    [self.view addSubview: self.textView];
}

Again...thanks so much!

Glasswing
Not an answer. Edit your question.
tc.
Sorry about that...you're right, I should have edited my question to post the additional code.
Glasswing