0

I am using a UIAlertView with a message Peer Disconnected.Back ground works/remaining codes are working without dismiss it.there is a button called Continue. I need to work the remaining codes only after the continue button click. and also I need to Quit my application in cancel button click.can any one tell me a good way to do it.

My Code is:

UIAlertView *alertView;  
alertView = [[UIAlertView alloc] initWithTitle:@"Peer Disconnected!" message:nil delegate:self cancelButtonTitle:nil otherButtonTitles:@"Continue", nil];
[alertView show];
[alertView release];
BenMorel
  • 34,448
  • 50
  • 182
  • 322
Vipin
  • 4,718
  • 12
  • 54
  • 81

3 Answers3

1

You can call UIAlertView's delegate method explained below......

 - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
 {
      if (buttonIndex == 0) {
          //Your Code   //For First Button
      } else if (buttonIndex == 1) {
          //Your Code   //For Second Button
      }
 }

Please follow this Link to quit the application

Community
  • 1
  • 1
Mehul Mistri
  • 15,037
  • 14
  • 70
  • 94
1

try this:-

UIAlertView *alertView;  
alertView = [[UIAlertView alloc] initWithTitle:@"Peer Disconnected!" message:nil delegate:self cancelButtonTitle:@"cancel" otherButtonTitles:@"Continue", nil];
[alertView show];
[alertView release];


- (void)alertView:(UIAlertView *)alert didDismissWithButtonIndex:(NSInteger)buttonIndex
{   
    if(buttonIndex==0)
    {
NSLog(@"cancel clicked");
    }
    else if(buttonIndex==1)
    {
NSLog(@"continue clicked");
    }
    }
Gypsa
  • 11,230
  • 6
  • 44
  • 82
0
UIAlertView *alertView;  
alertView = [[UIAlertView alloc] initWithTitle:@"Peer Disconnected!" message:nil delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Continue", nil];
[alertView show];
[alertView release];

Implement this delegate method.

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if(buttonIndex == alertView.cancelButtonIndex) {
// Cancel operation...
}else if (buttonIndex == alertView.firstOtherButtonIndex) {
// Continue operation...
}
}
  • basically i am a C# developer.tell me the code to quit my application in objective c. – Vipin Jun 02 '11 at 06:13
  • Refer posts http://stackoverflow.com/questions/355168/proper-way-to-exit-iphone-application and http://stackoverflow.com/questions/1707685/how-to-quit-an-iphone-app-nicely –  Jun 02 '11 at 06:15