Joseph Raj
Joseph Raj

Reputation: 13

UIAlertView cancel button return back to first view

I'm using Xcode 4.2 with storyboard.

My storyboard has navigation controller and root view, with a button on root view. I set the button to push to a second view controller. On click button, a pop up appears with Ok and Cancel button. If user clicks ok, it goes to second view. But how to I make the Cancel button to go back to root view?

Here's my code to check on which button is clicked.

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
  if (buttonIndex==0) // cancel button{
    [super viewWillAppear:YES]; // to go back to root view but not working
 }
}

Upvotes: 0

Views: 2426

Answers (2)

Bagus Cahyono
Bagus Cahyono

Reputation: 668

You Can use this. maybe can help.

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
  if (buttonIndex==0) // cancel button{
        [self dismissModalViewControllerAnimated:YES];
    }

Upvotes: 1

Mansi Panchal
Mansi Panchal

Reputation: 2357

In your code , just dismiss the Alert View , when

(buttonIndex==1)

Upvotes: 0

Related Questions