views:

4910

answers:

3

I have the following code in a method. When I run this in the simulator the debugger skips right over the code?? What am I missing?

if (([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeLeft) || 
  ([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeRight)) 

{


} else {


}
+2  A: 

Update 2

This shouldn't matter, but try turning on orientation notifications:

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];


[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(detectOrientation) name:@"UIDeviceOrientationDidChangeNotification" object:nil];


Update

My bad, I assumed it was empty.

Try removing the or statement and just test for a single orientation. See if that fixes it. Maybe there is a bracket problem or something silly.

I have the following test working in production code, so your technique should work:

    if (([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeLeft) || 
        ([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeRight)) {


}


Original Answer

You have to actually put statements in the if blocks to get it to step in.

The debugger is smart enough to skip over empty blocks.

Corey Floyd
Yes there data in the if and else; and Yes it skips over the whole thing.
Jordan
Thank you. It was a silly bracket problem I missed. Awesome.
Jordan
+3  A: 

Note that there's a macro UIDeviceOrientationIsLandscape and UIDeviceOrientationIsPortrait, so instead of comparing it separately to LandscapeLeft and LandscapeRight you could just do it like this:

if (UIDeviceOrientationIsLandscape([UIDevice currentDevice].orientation))
{
}
inkredibl