I am beginner to xcode programming.Please tell me how to display the alert message when we are going to click the button in xcode-iphone-4.3
My Code is as follows,
- (IBAction)buttonPressed:(id)sender{
UIAlertView* mes=[[UIAlertView alloc] initWithTitle:@"Hello World!!!!!!"
message:@"This is the Iphone app" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles: nil];
[mes show];
[mes release];
Please help me regarding this.
-(IBAction)buttonOnePressed:(id)sender
{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle: @"Clicked button 1"
message: @"Alert Message here"
delegate: self
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"OK",nil];
[alert setTag:1];
[alert show];
}
-(IBAction)buttonTwoPressed:(id)sender
{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle: @"Clicked button 2"
message: @"Alert Message here"
delegate: self
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"OK",nil];
[alert setTag:2];
[alert show];
}
Below is the delegate method to track which button on Alertview is hit.
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (alertView.tag == 1) { // UIAlertView with tag 1 detected
if (buttonIndex == 0)
{
NSLog(@"user pressed Button Indexed 0");
// Any action can be performed here
}
else
{
NSLog(@"user pressed Button Indexed 1");
// Any action can be performed here
}
}
else if (alertView.tag == 2) { // UIAlertView with tag 2 detected
if (buttonIndex == 0)
{
NSLog(@"user pressed Button Indexed 0");
// Any action can be performed here
}
else
{
NSLog(@"user pressed Button Indexed 1");
// Any action can be performed here
}
}
}
You can set tag to UIAlertView
in case you have more than one UIAlertView
s and can determine which UIAlertView
button is clicked in its delegate method clickedButtonAtIndex
using its respective tag.
In IBAction you have to write the code and give the Connections to the Button
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With