Results tagged “Programming” from Bill's Words

Here’s what I posted a few moments ago on stackoverflow.com, 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!

  • I like Markdown; it works very well. But it doesn’t have the ability to emphasize text with strikethroughs, which are a mainstay of modern conversation in blogs these days.

    So I modified it. Watch this:

    Here is a strikethrough.

    See how easy that was? All I did was type a dash before and after the word “strikethrough,” and Markdown now makes that into a strikethrough.

    To do this, all I did was modify the Markdown.pl code a bit. Here’s how you can do it, too.

    Find Markdown.pl. For MoveableType users, it’s in mt/plugins/Markdown. Edit it with your favorite editor and go to line 1040. Make that block of code look like this by adding the last two or three lines (you can credit me if you want):

    sub _DoItalicsAndBold {
        my $text = shift;
    
        # <strong> must go first:                                                                                                                                     
        $text =~ s{ (\*\*|__) (?=\S) (.+?[*_]*) (?<=\S) \1 }
            {<strong>$2</strong>}gsx;
    
        $text =~ s{ (\*|_) (?=\S) (.+?) (?<=\S) \1 }
            {<em>$2</em>}gsx;
    
        # These lines added by Bill Eccles, 2008-07-04
        $text =~ s{ (\s) (-) (?=\S) (.+?) (?<=\S) (-) }
        {$1<strike>$3</strike>}gsx;
    
        return $text;
    }
    

    Be forewarned that I’ve only tested it in very simple use (you’ve seen all the testing I’ve done, above) and that it might do unexpected things. But so far, so excellent good!

    UPDATE: I wonder if this will make problem for people who-make-use of words-with hyphens-randomly scattered throughout their text… YES! AGH!

    I’ll have to go work on that for a bit… back in a while.

    UPDATE: OK, that problem is fixed (as you can see above). It does fail, however, with striking through hyphenated words, (Here’s an example-.) but that’s OK in my book. Just leave out the hyphen—it’d be lost in the strikethrough anyway.