-(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];
}
A continuación se muestra el método delegado para rastrear qué botón en Alertview se golpeó.
-(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
}
}
}
Puede configurar etiqueta para UIAlertView
en caso de tener más de un UIAlertView
s y puede determinar qué UIAlertView
se hace clic en su método delegado clickedButtonAtIndex
usando su respectiva etiqueta.
Gracias por responder.pueden decirme cómo dar las conexiones al botón – rani
declarar el botón - (IBAction) Presentado: (id) remitente; en el archivo .h. Y vaya al archivo .xib. Y allí encontrará el FilesOwner. Haga clic derecho sobre él. Luego encontrará el método y arrastre eso al botón y luego mostrará popover. Allí encontrará el TouchUpInside.Connect it . – Tendulkar