UIAlertView example in Iphone


In this tutorial we will see how to enter the value to the text field and if we don't enter any value in text field then it will show the alert box.



1. Open the xcode & choose "File->New Project".

2. Select "Application" from left menu and then "View-based Application".

3.Name your project as "alertview" and save the project.

4.Now just select "alertviewViewController.h" file from left menu for define a  UITextField . Set the property for UITextField and define a method showalert as IBAction.



#import

@interface alertviewViewController : UIViewController {
    IBOutlet UITextField *t1;

}
-(IBAction)showalert:(id)sender;

@end


5. Now select "alertviewViewController.m" file from menu for implementation.

#import "alertviewViewController.h"

@implementation alertviewViewController
-(IBAction)showalert:(id)sender
{
    if(t1.text.length==0)
    {
        UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"alert view" message:@"Enter text" delegate:self cancelButtonTitle:@"ok" otherButtonTitles:@"cancel",nil];
        [alert show];
           
    }
    [t1 resignFirstResponder];

}
- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
   
    // Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}


- (void)dealloc {
    [t1 release];
    [super dealloc];
}

@end


6. Now double click on "alertviewViewController.xib" from Resource folder for open it.

7. On the view window drag the button and  textfield from library . Then link the textfield to the File's Owner. And link the button to IBActon method.

8. Then Quit and Save the Interface Builder.

9. Now you are ready for  click on "Build & Go" button.

Now you can see the output in iphone simulator .



(4) Responses to this post

Carly May 06 2011 at 00:09:44

That's not just the best answer. It's the btesset answer!

vfojzrac May 07 2011 at 06:40:28

cRbFgZ , [url=http://wijoxgdnlpbq.com/]wijoxgdnlpbq[/url], [link=http://idizutwbydzx.com/]idizutwbydzx[/link], http://vucafmlpukqi.com/

valium Mar 15 2012 at 02:04:40

http://www.shopdiazepamfast.com/ - buy valium online no rx buy cheap online valium valium no prescriptions buy valium online cheap http://www.shopdiazepamfast.com/

cnowrzkl Apr 15 2012 at 17:02:42

5vjFsZ zrgdsccfvmui, [url=http://uqvhqewhljvj.com/]uqvhqewhljvj[/url], [link=http://olezbtzdejal.com/]olezbtzdejal[/link], http://zpdltgkfhkey.com/


Leave your comment here






User Login




New User Forgot password

Newsletter Subscribe

Advertisement

 
 
 
quick contact