Button Press Pop Up Alert
Introduction:
Hey guys, in this tutorial I will be teaching you how to make a pop up alert in your application. What a pop up alert does is when a user taps a button an alert will pop up with some information and you can dismiss it once your done reading. Its a simple application however the code is quite long so be sure to use the picture follow ups as well as a video I am going to add on when we go into IB.
Step 1:
Open up Xcode, go to File, New Project, and select a View Based Application. Title the application whatever fits your needs however I am going to title it PopUpAlert.
Step 2:
Now that we have set up our Project go into our Nib Files and double click the ViewController.xib. Here I will add a video tutorial to show you what to do in IB with adding the button as well as the action. I feel that I should do this more often seeing as text isn’t the best way to teach IB especially when first starting out in iPhone Development.
Step 3:
As you can see in your products folder you have your MainView.m and your MainView.h. We are going to go ahead and drag those into our Classes folder and select the .h folder to start up the coding process for the pop up alert.
Step 4:
In your MainView.h highlight all the green text starting from /* and replace the green text with UIView. Make sure your open bracket sign is one space after UIView otherwise Xcode will not recognize that it is the start of an open bracket after text has been inputed.
Step 5:
Everything is done in our .h folder so now we can go to our .m folder and start up some heavy coding where we will action add the action code to make the pop up alert. After – (IBAction)alert { hit enter two times and you are going to input the code that I will show below.
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@”Pop up Alert” message:@”POP UP TIME” delegate:nil cancelButtonTitle:@”Dismiss” otherButtonTitles:nil];
[alert show];
[alert release];
(the second line above should still be attaching after nil followed by a space however Wordpress doesn’t give me enough space)
Step 6:
Now that you are completely done with your application you can go File, Save and hit Build and Go and this is what your outcome of your application should come out to.
- Thanks
http://www.protocalldev.net FOR MORE XCODE TUTORIALS!
Reader Comments (4)
THANKS FOR SCREAMING AT ME
@Guy, sorry about that. I fixed Anthony's title.
Thanks David
My bad lol didnt notice that