How to go to the next view controller after displaying alertview

I have an iPhone and I want it to display AlertView and click OK after this view needs to be changed, but this does not happen.

  UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Thank you" message:@"" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alert show]; [alert release]; return; [self moveToView]; -(void)moveToView { MainViewController*targetController=[[MainViewController alloc]init]; [self.navigationController pushViewController:targetController animated:YES]; } 
+4
source share
6 answers

Use UIAlertViewDelegate

 - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { // Code to move to next view [self moveToView]; } 

Note : run UIAlertViewDelegate in the interface declaration. Also, when declaring a UIAlertView, set the delegate to itself.

Hope this helps you.

+7
source

Simple Insert a UIAlertViewDelegate and enter the code there.

 - (void) alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex { MainViewController*targetController=[[MainViewController alloc]init]; [self.navigationController pushViewController:targetController animated:YES]; [targetController release]; } 
+6
source

in .h, implemented by UIAlertViewDelegate

  @interface ClassName : ParentClassName <UIAlertViewDelegate> 

in .m, add this method,

 - (void)alertView:(UIAlertView *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex { [self moveToView]; } 
+5
source

Implement delegate submission of warnings:

In your file yourClass.h:

 @interface yourClass : UIViewController<UIAlertViewDelegate>{ } @end 

In your file yourClass.m:

 @implementation yourClass - (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex{ [self moveToView]; } @end 
+4
source

Well, you are setting yourself up as a UIAlertView delegate. This is correct, and this is the first step that you must take. After that, execute this method:

 - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { [self moveToView]; } 

Here you can also make a switch statement to see which button was pressed. But since you only have the OK button on the AlertView, this is not necessary.

Hope this helps.

Hooray!

+3
source

Add your code to the - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex , and add the UIAlertViewDelegate to your .h ... file.

 - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{ NSLog(@"The index: %d",buttonIndex); MainViewController*targetController=[[MainViewController alloc]init]; [self.navigationController pushViewController:targetController animated:YES]; [targetController release]; } 

I think it will be useful for you.

+2
source

All Articles