OK, knowledgeable programm开发者_如何学Goer-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:
/*
// 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.)
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!
The answer is in the question, namely that the shouldAutorotateToInterfaceOrientation method is enclosed by comment tokens. Removing the "/*
" and "*/
" which precede and follow the method solved the problem.
精彩评论