警告 - 其视图不在IOS 9的窗口层次结构中

时间:2015-10-15 05:21:39

标签: ios objective-c

我创建了两个视图控制器#ifndefViewControllerOne。我给了DetailViewController一个动作,当按下按钮时它将转到第二个视图控制器,

UIButton

但它给出了错误,

- (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];


            });  }

按下按钮后,它移动到<ViewController: 0x7f97e9da7d60> whose view is not in the window hierarchy! ,但屏幕为黑色,但未显示DetailViewController中的详细信息。

1 个答案:

答案 0 :(得分:2)

如果您已在故事板中添加了DetailViewController,则可能必须在实例化时从故事板中引用相同内容

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

当您使用alloc / init启动时,它只是实例化一个空白视图控制器。