Present View Controller not working with ios 9

11,742

Solution 1

Make sure the presentedViewController is nil. If presentedViewController is not nil change the code to following.

RegistrationViewController * viewController =[[UIStoryboard storyboardWithName:@"Registration" bundle:nil] instantiateViewControllerWithIdentifier:@"RegistrationViewController"];

if ([self presentedViewController]) {
    [[self presentedViewController] dismissViewControllerAnimated:NO completion:^{
        dispatch_async(dispatch_get_main_queue(), ^{
            [self presentViewController:viewController animated:YES completion:nil];
        });
    }];
} else {
    [self presentViewController:viewController animated:YES completion:nil];

}

Solution 2

try viewDidAppear in

  -(void)viewDidAppear:(BOOL)animated{ 
         [self presentViewController:viewController animated:YES completion:nil];
    }
Share:
11,742

Related videos on Youtube

Aarti Oza
Author by

Aarti Oza

Updated on June 04, 2022

Comments

  • Aarti Oza
    Aarti Oza almost 2 years

    Present view controller is not working with ios 9, when I press the button it not redirected to present view controller.

    Why this happens ?

    I had tried the below code

     RegistrationViewController * viewController =[[UIStoryboard storyboardWithName:@"Registration" bundle:nil] instantiateViewControllerWithIdentifier:@"RegistrationViewController"];
     [self presentViewController:viewController animated:YES completion:nil];
    

    I had also tried the below code

     UIStoryboard* storyboard = [UIStoryboard storyboardWithName:@"Registration"
                                                             bundle:nil];
     RegistrationViewController *add =
     [storyboard instantiateViewControllerWithIdentifier:@"RegistrationViewController"];
     [self presentViewController:add animated:YES completion:^{
            dispatch_async(dispatch_get_main_queue(), ^{
                [self presentViewController:add
                                   animated:YES
                                 completion:nil];
            });
      }];
    

    Edit

    My complete code here. I am using Xcode 7 and running it with ios 9

    #import "LoginViewController.h"
    #import "RegistrationViewController.h"
    
    @interface LoginViewController ()
    
    @end
    
    @implementation LoginViewController
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        // Do any additional setup after loading the view.
    }
    
    - (void)didReceiveMemoryWarning {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
    }
    
    
    - (IBAction)actionRegistrationClicked:(id)sender
    {
        RegistrationViewController * viewController =[[UIStoryboard storyboardWithName:@"Registration" bundle:nil] instantiateViewControllerWithIdentifier:@"RegistrationViewController"];
         [self presentViewController:viewController animated:YES completion:nil];
    
    }
    @end
    

    Registration view controller

    #import "RegistrationViewController.h"
    
    @interface RegistrationViewController ()
    
    @end
    
    @implementation RegistrationViewController
    
    - (void)viewDidLoad
    {
        [super viewDidLoad];
        // Do any additional setup after loading the view.
    }
    
    - (void)didReceiveMemoryWarning
    {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
    }
    
    @end
    
    • Teja Nandamuri
      Teja Nandamuri
      I wondered y it isnt working.do u want to team view or send the source code :P @Florence
    • ProblemSlover
      ProblemSlover
      @Florence Can you put your complete code into pastebin.?
    • ProblemSlover
      ProblemSlover
      @Florence I doubt that controller is being initialized . Please make sure again setting debug point inside your action method that view controller instance is initialized and it's an instance of RegistrationViewController by casting to view controller as follows: (RegistrationViewController*)[[UIStoryboard storyboardWithName:@....
  • Surya Subenthiran
    Surya Subenthiran over 8 years
    did you get any warning while presenting the viewcontroller?
  • Balaji Kondalrayal
    Balaji Kondalrayal over 8 years
    I think you are presenting the same viewController you are already in.
  • Aarti Oza
    Aarti Oza over 8 years
    no way, I am in login view controller and I am gonna to present registration view controller.
  • Ratul Sharker
    Ratul Sharker over 8 years
    Its not necessary that login & registration view controller to be in same storybaord.@balaji
  • Nat
    Nat over 6 years
    Always call super in such methods.