Switch views from alert view options in xcode

439 Views Asked by At

I want to move to other views created in storyboard through alert view menu buttons displayed in home page. An alert view gives the list of buttons containing different views.
How can I move to those views.
I am using

-(void) alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 1){

}
if (buttonIndex ==2) {

}
if(buttonIndex == 3){


}

}
1

There are 1 best solutions below

0
zahreelay On

First you need to get an instance of the storyboard.
Then you instantiate your Viewcontrollers using the storyboard.
Then you push onto the navigation stack as usual.

-(void) alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"storyboard_name" bundle:nil];

    if (buttonIndex == 1)
    {
        ViewController1 *vc1 = (ViewController1 *)[storyboard instantiateViewControllerWithIdentifier:@"view1"];
        [self.navigationcontroller pushViewController:vc1];
    }
    if (buttonIndex ==2)
    {
        ViewController2 *vc2 = (ViewController1 *)[storyboard instantiateViewControllerWithIdentifier:@"view2"];
        [self.navigationcontroller pushViewController:vc2];
    }
    if(buttonIndex == 3)
    {
    }
}