Friday, April 24, 2009

Alert box in iPhone

An alert box is a quick way to communicate to your users. Alert boxes look like a rounded square with a message and a button on it. You may put this code into your project to get an alert box:
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"UIAlertView"
message:@"Hi There!" delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles: nil];

[alert show];
[alert release];

As you can see from the code above, square brackets are the order of the day in Objective-C, the iPhone programming language. For now, note that text that comes right after the word "message:". This is where you control what the alert box presents to the user.
Finally, notice the overall pattern of using objects in Objective-C: alloc, "do stuff", release. This is something that you will be using often in your iPhone programming.

No comments: