2010-07-23 19 views
9

Tenía curiosidad acerca de cómo puedo adjuntar una tarea diferente al otherButtonTitle de UIAlertView. El botón cancelar lo saca automáticamente de la aplicación, pero si deseo adjuntar una tarea diferente con el otro título de botón, ¿qué debo hacer?otherButtonTitles en UIAlertView

Gracias,

Respuesta

22

UIAlertView delegado "didDismissWithButtonIndex" las llaman cada vez que u haga clic en cualquier botón.

Prueba esto:

UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"Message" 
               message:messageString 
               delegate:self 
             cancelButtonTitle:@"Back" 
             otherButtonTitles:@"Reply",@"Delete",nil]; 
[alert show]; 
[alert release]; 


- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex 
{ 
    if (buttonIndex == 1) 
    { 
    NSLog(@"Reply"); 
    UIAlertView *myalert = [[UIAlertView alloc] initWithTitle:@"Button Clicked" message:@"U clicked Reply " delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; 

    [myalert show]; 
    [myalert release]; 
    } 

    if (buttonIndex == 2) 
    { 
    NSLog(@"Delete"); 
    UIAlertView *myalert = [[UIAlertView alloc] initWithTitle:@"Button Clicked" message:@"U clicked Delete " delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; 

    [myalert show]; 
    [myalert release]; 
    } 
} 
no
+0

Su dong nada cuando hago clic en cualquiera de esos botones. – Ashutosh

+0

encontrar código actualizado – iPhoneDev

+0

Corregir respuesta. Consejo: No confunda 'didDismissWithButtonIndex' (invocado * después de * que UIAlertView abandone la jerarquía de la pantalla) con' clickedButtonAtIndex' (invocado mientras el UIAlertView todavía está en pantalla y aún forma parte de, y afecta dramáticamente, la jerarquía de la vista de pantalla). Encontré esta confusión en otras respuestas de StackOverflow y otros lugares en la web. –