views:

1317

answers:

3

I have the following code which evaluates to true and runs the code inside the braces I rotate to the right (or left) in OS 2.2.1. However the same line of code does not evaluate to true (or go into the braces) if compiled and run for OS 3.0...

I say this because in the debugger (and the log) the lines inside the braces get skipped if I've compiled for 3.0

This is inside of a textViewDidBeginEditing method on a textView...

Did something change between 2.x and 3.0 relative to how this is handled? The non-resizing text field has been noticed by users as a bug I'm trying to fix...

This isn't my code originally and as I look at it, I'm beginning to think I should be implementing some delegate methods for rotation...? But it still bugs me that this statement isn't working...

Thanks in advance for any advice...

if((self.interfaceOrientation == UIInterfaceOrientationLandscapeLeft)||(self.interfaceOrientation == UIInterfaceOrientationLandscapeRight))
{
 [self setTextViewHeight:107];
 NSLog(@"inside if self.interfaceorientation...");

}
A: 

Try a log statement before the textviewheight assignment if you want to test if this block is entered (& not if it is exited early by error in assignment)

Devin Ceartas
Thanks - yes I did that... logged all over the place. I also set a breakpoint at the top of the method and stepped through the code and watched the if block get skipped in 3.0 and executed in 2.x...I just took most of them out for readability...
A: 

I don't know why, but this view controller doesn't know it's own interfaceOrientation. I assume it has to do with the fact that it's "inside" a UITabBarController... And the "new way" of handling this that Apple changed with 3.0.

Clarifying comments on that "change" are welcomed!

Bottom line, self.interfaceOrientation was always evaluating to 1 ("Up") no matter how the device was rotated...

I solved this by changing the reference and using MyTabBarController.interfaceOrientation instead, as the TabBarController "superclass" seemed to reliably "know" what the device's orientation was.

(Of course, I had to give this class a reference to MyTabBarController, done when MyTabBarController loads all the UIViewControllers into itself...) This already existed in the code...

Given that reference, the following simple change gave me access to the "true" state of the rotation... and this code ran when expected...

if ((myTabBarController.interfaceOrientation == UIDeviceOrientationLandscapeLeft) || (myTabBarController.interfaceOrientation == UIDeviceOrientationLandscapeRight)) {
    [self setTextViewHeight:116];
An explanation for this behavior from the view Controller Programming Guide:"In an iPhone application, the window object does much of the work associated with changing the current orientation ... Specifically, it works with the view controller whose root view was most recently added to, or presented in, the window. In other words, the window object works only with the frontmost view controller whose view was displayed using one of the mechanisms described in “Presenting a View Controller’s View.”
jemmons
A: 

More useful information (and a nice method to know when orientation changes) can be found here:

http://blog.sallarp.com/shouldautorotatetointerfaceorientation/