2012-01-18 9 views
7

soy principiante a Xcode programming.Please dime cómo mostrar el mensaje de alerta cuando vamos a hacer clic en el botón en Xcode-iPhone-4.3Mensaje de alerta para el clic de botón en iPhone SDK 4.3

Mi código es como sigue,

- (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]; 

Por favor, ayúdenme con respecto a esto.

Respuesta

22
-(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.

0

Crea IBAction para tu botón y agrega el código para la vista de alerta en ese método.

1

En IBAction usted tiene que escribir el código y darle las conexiones con el botón

+0

Gracias por responder.pueden decirme cómo dar las conexiones al botón – rani

+0

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

Cuestiones relacionadas