Loading..
Loading..
« 35 free fantasy creature designs and spritesheets | Main | Updating an iPhone OS 3.x project (w/ AdMob integrated) to build for iOS 4.0, using Xcode 3.2.3 »
Sunday
Jul252010

Seeing SIGABRT on [UIButton buttonWithType: initWithFrame:] in iOS 4.0?

It's likely because you shouldn't have been calling it the first place.

For whatever reason (and I honestly don't know why), we were using the following call in an originally iPhone 3.x compiled app:

UIButton *btn=[[UIButton buttonWithType:UIButtonTypeRoundedRect] 
   initWithFrame:CGRectMake(x, y, w, h)];

Turns out this worked in 3.x (and still works on apps compiled against a 3.x base SDK), but when compiled against a 4.x base SDK causes a [NSException raise:format:arguments:] exception on init-ing the button.

Anyway, fix is simple enough - init the UIButton as it was meant to be (SDK class refererence):

UIButton *btn=[UIButton buttonWithType:UIButtonTypeRoundedRect];
[btn setFrame:CGRectMake(x, y, w, h)];

Order restored, compiling fine against iOS 4.0 (well, 4.0.1 now) base SDK. No idea why the combined init worked before, but simple enough to resolve.   

Reader Comments

There are no comments for this journal entry. To create a new comment, use the form below.

PostPost a New Comment

Enter your information below to add a new comment.

My response is on my own website »
Author Email (optional):
Author URL (optional):
Post:
 
Some HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>