Warning - whose view is not in the window hierarchy in IOS 9

I created two view controllers, ViewControllerOne and DetailViewController . And I gave an action to a UIButton, when the button is pressed it will go to second view controller,

- (IBAction)loginButtonPressed:(UIButton *)sender {
self.loginButton.hidden= YES;
self.aview.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"authentication.png"]];

LAContext* context = [[LAContext alloc]init];
NSError* error = nil;

if ([context canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&error]) {
    [context evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason:@"Authenticate with Touch ID" reply:^(BOOL success, NSError*error){
        if (success) {
            dispatch_async(dispatch_get_main_queue(), ^{
                self.loginButton.hidden= NO;
                self.aview.backgroundColor = [UIColor clearColor];
                DetailViewController* detailViewController = [[DetailViewController alloc]init];
              [self presentViewController:detailViewController animated:YES completion:nil];


            });  }

but its giving the error,

<ViewController: 0x7f97e9da7d60> whose view is not in the window hierarchy!

When button pressed its moves to DetailViewController but the screen is black, its not showing the details in DetailViewController.

Upvotes: 1

Views: 751

Answers (1)

Rashmi Ranjan mallick
Rashmi Ranjan mallick

Reputation: 6620

If you have added your DetailViewController in storyboard, you may have to refer the same from storyboard while instantiating.

UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"your_storyboard_name" bundle: nil];
DetailViewController *detailViewController = (DetailViewController*)[mainStoryboard instantiateViewControllerWithIdentifier: @"your_storyboard_identifier"];
[self presentViewController:detailViewController animated:YES completion:nil];

When you are initiating using alloc/init, it's simply instantiating a blank view controller.

Upvotes: 2

Related Questions