Laugh at My Fail: A n00b vs. iPhone Autorotate

| | Comments (3)

Here’s what I posted a few moments ago on, a great site for getting clues regarding programming problems from the very esoteric to the very, ahem, basic:

OK, knowledgeable programmer-types, please be gentle…

I’m having trouble getting a very simple, one-view “Hello World” app to rotate automatically. I go through the usual “Hello World” steps:

  • Create a new View-based project.
  • Double-click on the .xib file for the ViewController.
  • Add a item from the Library. I’ve tried a Label as well as a Slider.
  • Change the Struts and Springs to just Springs to keep the item in the middle of the view.
  • Save and then edit the .m file for the ViewController so that it reads:
  • /*
    // Override to allow orientations other than the default portrait orientation.
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation {
        // Return YES for supported orientations
        return YES;

    (Um… Duh. I just saw it. But I will continue with my story for your amusement.)

  • Save, build, run, rotate, and notice that nothing rotates when I rotate the iPhone simulator. And, no, I didn’t rotate my laptop… I used the keyboard shortcuts!

    Frustration set in after about an hour of Googling for the answer. Everywhere I looked, each source said the same thing: Just change the return value to “yes”. And yet…

    I even stuck debugger breakpoints in! None of them were hit! (Shock, surprise!) Figuring that I didn’t know how to use the debugger, I stuck a breakpoint in on “initWithNibName.” Guess what?! That didn’t get hit, either! What the… heck?!

    So I downloaded Apple’s WhichWayIsUp app to test my breakpoint l33t breakpoint skilz. Sure enough, it beeps away as I rotate the “iPhone” around. So what am I doing wrong?!

    Surely, I’m not that ignorant that I… no, wait, I take that back. If you saw my error, above, then you are certainly thinking, “Yes, he is that ignorant.” And you’re right.

    For those of you who stumbled across this question, are similarly frustrated, and didn’t see the problem yet, here’s the answer: the entire shouldAutorotateToInterfaceOrientation method is encapsulated by “/* */” comment tokens. It never got compiled, much less called.

    Now, that I know of, none of the sources that I found make it obvious that you have to ensure that the code block is uncommented. Several say, “All you have to do is change exactly one line of code.” And, except for those other two with the comment tokens on them, they’re exactly right.

    If I just helped some other n00b, then great. If I made you laugh at my fail, then that’s even better.

    Thanks, everybody, for your help!


    Greg said:

    Aww poor guy! We've all been there at some point though.

    Joel Bernstein said:

    Did you have syntax highlighting turned off?

    Bill Eccles said:

    Actually, code coloring/syntax highlighting was on... that's how oblivious I was to the problem!

    Now I know...