How to Show an Alert with UIAlertView
Showing an alert message to the user isn’t just a handy interface lick, it’s also an invaluable debugging tool. Thankfully, this functionality is built into the iPhone SDK.
To pop an alert with a title, message and OK button, we use the UIAlertView class like so:
UIAlertView *alert = [[UIAlertView alloc] initWithTitle: @"Announcement" message: @"It turns out that you are playing Addicus!" delegate: nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alert show]; [alert release];
But what if you want to have more than one button on the alert and collect user input from it? Well that is pretty simple too. To do that, you first need to create a class that employs the UIAlertViewDelegate delegate like so:
@interface MyClass : NSObject <UIAlertViewDelegate>
Then, in your class, you need to override the alertView method in order to receive input like so:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { if (buttonIndex == 0) { NSLog(@"user pressed OK"); } else { NSLog(@"user pressed Cancel"); } }
Finally, we create the UIAlertView and pass in the delegate. Also note that we’ve labeled the Cancel button “Cancel” and added the “OK” button to the other button titles, which differs slightly from the above example.
UIAlertView *alert = [[UIAlertView alloc] initWithTitle: @"Announcement" message: @"It turns out that you are playing Addicus!" delegate: MY_DELEGATE cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK",nil]; [alert show]; [alert release];
Addicus Gets Reviewed by AppSlappy

Scott Johnson reviewed Addicus on this week’s episode of AppSlappy. Some highlights:
- “weird little game”
- “addicting”
- “really digging it”
- “4 out of 5 stars”
- “highly recommend it”
Do listen to the whole show, because it is awesome, but if you want to skip right to the Addicus review then it starts during minute 23.
How to Open a URL in Safari
Tis the season to broaden your iPhone dev chops! We have been developing on the iPhone platform for about 6 months now and it turns out that in that time, you tend to learn lots of little tips and tricks. Since we’re overcome by the spirit of giving around this time of year, we are going to be posting 24 of these bite-sized iPhone development tips, 1 every day between now and Christmas day. Consider it an advent calendar of iPhone dev tip goodies.
On With The First Tip!
Say you would like to open a URL in Safari. We used this on the “Get Set” button on the main menu of Addicus. Here is how to do it with just one line of code using the UIApplication class:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://getsetgames.com/"]];








