tag:blogger.com,1999:blog-91054317286163914182024-03-13T16:26:53.536-07:00iPhone Applications Guruyasirhttp://www.blogger.com/profile/15485770447665471886noreply@blogger.comBlogger1125tag:blogger.com,1999:blog-9105431728616391418.post-41287531602383552922012-07-14T02:54:00.000-07:002012-07-14T04:03:22.171-07:00<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgDN4O5V1tmEQGZFIoZQDRjupjgD_kqLjbOevhKAIkpvWsk6ZmCL0-I-YsAv9kplcXszdwaEe-L7cWiZrSahgBY4vu9t3i7efxTIkXvfYvXuUGAMZTpuHzQtt22hfXQXkOGWzHyt6RGG6D1/s1600/draft_lens19584517_1340787297_.png" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgDN4O5V1tmEQGZFIoZQDRjupjgD_kqLjbOevhKAIkpvWsk6ZmCL0-I-YsAv9kplcXszdwaEe-L7cWiZrSahgBY4vu9t3i7efxTIkXvfYvXuUGAMZTpuHzQtt22hfXQXkOGWzHyt6RGG6D1/s320/draft_lens19584517_1340787297_.png" width="222" /></a></div>
This tutorial is for people who are new in iPhone programing environment and want to learn the basics of the iPhone programing.The alert view is used when you want to show any message to user and also it can be used as a debugging tool for checking any variable at runtime of application.<br />
Now it is the time of action to develop an iPhone application showing alert view .we will describe step by step to develop<br />
1.Using xcode create a new view based iPhone application project and name it AlertView.<br />
2.There will be six files created in your left side namely<br />
<blockquote class="tr_bq">
(i).AlertViewAppDelegate.h<br />
(ii)AlertViewAppDelegate.m<br />
(iii)MainWindow.xib<br />
(iv)AlertViewViewController.h<br />
(v)AlertViewViewControlle.m<br />
(vi)AlertViewViewControlle.xib</blockquote>
<br />
In these six files open the AlertViewViewController.h file and add alertview delegatd<br />
<br />
<div style="background-color: #f1c232;">
#import UIKit.h></div>
<div style="background-color: #f1c232;">
<br /></div>
<div style="background-color: #f1c232;">
@interface AlertViewViewController : UIViewController {</div>
<div style="background-color: #f1c232;">
<br /></div>
<div style="background-color: #f1c232;">
}</div>
<div style="background-color: #f1c232;">
<br /></div>
<div style="background-color: #f1c232;">
@end</div>
<br />
Now open the AlertViewViewController.m file and it will look like so as described below<br />
<br />
<div style="background-color: #fce5cd;">
#import "alertViewsViewController.h"</div>
<div style="background-color: #fce5cd;">
<br /></div>
<div style="background-color: #fce5cd;">
@implementation alertViewsViewController</div>
<div style="background-color: #fce5cd;">
<br /></div>
<div style="background-color: #fce5cd;">
- (void)dealloc</div>
<div style="background-color: #fce5cd;">
{</div>
<div style="background-color: #fce5cd;">
<br /></div>
<div style="background-color: #fce5cd;">
[super dealloc];</div>
<div style="background-color: #fce5cd;">
}</div>
<div style="background-color: #fce5cd;">
<br /></div>
<div style="background-color: #fce5cd;">
- (void)didReceiveMemoryWarning</div>
<div style="background-color: #fce5cd;">
{</div>
<div style="background-color: #fce5cd;">
// Releases the view if it doesn't have a superview.</div>
<div style="background-color: #fce5cd;">
[super didReceiveMemoryWarning];</div>
<div style="background-color: #fce5cd;">
<br /></div>
<div style="background-color: #fce5cd;">
// Release any cached data, images, etc that aren't in use.</div>
<div style="background-color: #fce5cd;">
}</div>
<div style="background-color: #fce5cd;">
<br /></div>
<div style="background-color: #fce5cd;">
#pragma mark - View lifecycle</div>
<div style="background-color: #fce5cd;">
<br /></div>
<div style="background-color: #fce5cd;">
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.</div>
<div style="background-color: #fce5cd;">
- (void)viewDidLoad</div>
<div style="background-color: #fce5cd;">
{</div>
<div style="background-color: #fce5cd;">
<br /></div>
<div style="background-color: #fce5cd;">
[super viewDidLoad];</div>
<div style="background-color: #fce5cd;">
}</div>
<div style="background-color: #fce5cd;">
<br /></div>
<div style="background-color: #fce5cd;">
- (void)viewDidUnload</div>
<div style="background-color: #fce5cd;">
{</div>
<div style="background-color: #fce5cd;">
[super viewDidUnload];</div>
<div style="background-color: #fce5cd;">
// Release any retained subviews of the main view.</div>
<div style="background-color: #fce5cd;">
// e.g. self.myOutlet = nil;</div>
<div style="background-color: #fce5cd;">
}</div>
<div style="background-color: #fce5cd;">
<br /></div>
<div style="background-color: #fce5cd;">
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation</div>
<div style="background-color: #fce5cd;">
{</div>
<div style="background-color: #fce5cd;">
// Return YES for supported orientations</div>
<div style="background-color: #fce5cd;">
return (interfaceOrientation == UIInterfaceOrientationPortrait);</div>
<div style="background-color: #fce5cd;">
}</div>
<div style="background-color: #fce5cd;">
<br /></div>
<div style="background-color: #fce5cd;">
@end</div>
<div style="background-color: white;">
<br /></div>
<div style="background-color: white;">
AlertView is a view which is not present in object liberary so we have to create it programatically how we can do this is described below</div>
<div style="background-color: white;">
<br /></div>
<div style="background-color: white;">
UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"Hello world" message:@"This is an alert view" delegate:self cancelButtonTitle:@"ok" otherButtonTitles:nil];</div>
<div style="background-color: white;">
In this way we create an object of class UIAlertView and set the title "Hello world" and the message "This is an alert view " and the title of button as ok.</div>
<div style="background-color: white;">
Here we have also to show alert view and for this we have use UIAlertView class method "show" to show alertview on the screen.</div>
<div style="background-color: white;">
And that method is implemented as below in the code</div>
<div style="background-color: white;">
<br /></div>
<div style="background-color: white;">
[alert show];</div>
<div style="background-color: white;">
so we will implement these two lines in the viewDidLoad method .And our code will be look like so</div>
<div style="background-color: white;">
<br /></div>
<div style="background-color: #cfe2f3;">
#import "alertViewsViewController.h"</div>
<div style="background-color: #cfe2f3;">
<br /></div>
<div style="background-color: #cfe2f3;">
@implementation alertViewsViewController</div>
<div style="background-color: #cfe2f3;">
<br /></div>
<div style="background-color: #cfe2f3;">
- (void)dealloc</div>
<div style="background-color: #cfe2f3;">
{</div>
<div style="background-color: #cfe2f3;">
<br /></div>
<div style="background-color: #cfe2f3;">
[super dealloc];</div>
<div style="background-color: #cfe2f3;">
}</div>
<div style="background-color: #cfe2f3;">
<br /></div>
<div style="background-color: #cfe2f3;">
- (void)didReceiveMemoryWarning</div>
<div style="background-color: #cfe2f3;">
{</div>
<div style="background-color: #cfe2f3;">
// Releases the view if it doesn't have a superview.</div>
<div style="background-color: #cfe2f3;">
[super didReceiveMemoryWarning];</div>
<div style="background-color: #cfe2f3;">
<br /></div>
<div style="background-color: #cfe2f3;">
// Release any cached data, images, etc that aren't in use.</div>
<div style="background-color: #cfe2f3;">
}</div>
<div style="background-color: #cfe2f3;">
<br /></div>
<div style="background-color: #cfe2f3;">
#pragma mark - View lifecycle</div>
<div style="background-color: #cfe2f3;">
<br /></div>
<div style="background-color: #cfe2f3;">
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.</div>
<div style="background-color: #cfe2f3;">
- (void)viewDidLoad</div>
<div style="background-color: #cfe2f3;">
{</div>
<div style="background-color: #cfe2f3;">
UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"Hello world" message:@"This is an alert view" delegate:self cancelButtonTitle:@"ok" otherButtonTitles:nil];</div>
<div style="background-color: #cfe2f3;">
[alert show];</div>
<div style="background-color: #cfe2f3;">
[super viewDidLoad];</div>
<div style="background-color: #cfe2f3;">
}</div>
<div style="background-color: #cfe2f3;">
<br /></div>
<div style="background-color: #cfe2f3;">
- (void)viewDidUnload</div>
<div style="background-color: #cfe2f3;">
{</div>
<div style="background-color: #cfe2f3;">
[super viewDidUnload];</div>
<div style="background-color: #cfe2f3;">
// Release any retained subviews of the main view.</div>
<div style="background-color: #cfe2f3;">
// e.g. self.myOutlet = nil;</div>
<div style="background-color: #cfe2f3;">
}</div>
<div style="background-color: #cfe2f3;">
<br /></div>
<div style="background-color: #cfe2f3;">
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation</div>
<div style="background-color: #cfe2f3;">
{</div>
<div style="background-color: #cfe2f3;">
// Return YES for supported orientations</div>
<div style="background-color: #cfe2f3;">
return (interfaceOrientation == UIInterfaceOrientationPortrait);</div>
<div style="background-color: #cfe2f3;">
}</div>
<div style="background-color: #cfe2f3;">
<br /></div>
<div style="background-color: #cfe2f3;">
@end</div>
<script type="text/javascript">
var infolinks_pid = 1056211;
var infolinks_wsid = 0;
</script>
<script src="http://resources.infolinks.com/js/infolinks_main.js" type="text/javascript">
</script>
<br />
Now save your code and run.Now the application will launch and an alert view will be shown on the screen</div>yasirhttp://www.blogger.com/profile/15485770447665471886noreply@blogger.com0