Tuesday, February 09, 2010

iPhone Dev tip - Note To Self

This is pretty much a note to self but might help some other poor shmuck out there who fails to notice, as I did, a seemingly unimportant bit of a reference page.

Here is the problem - You create and initialise a UIAlertView or UIActionSheet object and your application crashes with EXC_BAD_ACCESS. "How can this be?" you wonder, it's a brand new object, how the hell is it accessing bad memory?

Well the error is misleading, in fact you have probably not read the reference page right. If you fail to terminate the otherButtonTitles parameter with a nil like this:

UIAlertView *myAlertView = [[UIAlertView alloc] 
                           initWithTitle:@"some title" 
                                 message:@"a message"
                                delegate:delegate 
                       cancelButtonTitle:@"cancel" 
                       otherButtonTitles:@"foo", nil]

Then you get the EXC_BAD_ACCESS error, not, as you might reasonably expect an error telling you that the parameters were wrong.

I lost a lot of hours learning that so you don't have to.

1 comments:

Unknown said...

Hi Rick,
Sorry for hijacking this post. I didn't find another method to get in touch with you.

My name is Flo and I'm trying to achieve the same thing you did in this thread: http://cliqklabs.com/forum/viewtopic.php?p=171&sid=f52983a84eb9a7aa348e4a4a87ef0322

Your post is from 2008, so I wasn't sure you would have gotten this question if I posted it on the that forum.

I think you use the obj-c wrapper methods instead of writing plain c, aren't you? Did you manage to compile the framework, or did you just packed all the sources in your project and bended the includes?

I would be delighted if you could drop my a few lines (f.anselstetter [at] googlemail [dot] com) how you managed to get it working.

Bye Flo