提出流行音乐

时间:2015-12-26 22:36:53

标签: ios swift uiviewcontroller

所以我现在有一个弹出窗口,当用户按下按钮时会显示给用户。我遇到的问题是我似乎无法忽略这个视图控制器,然后呈现按下按钮时应该出现的视图控制器。

无论如何解雇一个视图控制器但仍然出现另一个是我的代码在下面?

@IBAction func unlockButtonDidTouch(sender: AnyObject) {

    dismissViewControllerAnimated(true) {() -> Void in
        let storyboard = UIStoryboard(name: "Main", bundle: nil)
        let vc = storyboard.instantiateViewControllerWithIdentifier("unlockVC") as! UnlockViewController
        self.presentViewController(vc, animated: true, completion: nil)
    }
}

这是按下按钮后出现的错误。

2015-12-25 19:34:40.008 Corral [771:165154]警告:尝试显示其视图不在窗口层次结构中!

2 个答案:

答案 0 :(得分:0)

您无法在完成区内调用self.presentViewController(vc, animated: true, completion: nil)。因为您的contentViewController已被驳回。这意味着此时selfnil。因此,您应该从显示UIPopoverController

的另一个视图控制器执行此任务

答案 1 :(得分:0)

为了补充卢卡斯的答案,一种方法可能是使用NSNotifications来做到这一点。您在创建弹出窗口时创建观察者/通知,并且在此视图控制器文件中还有一个方法可以显示新的视图控制器。然后,您可以在弹出窗口中按下此按钮时发布通知/运行此方法。

在显示popover的视图控制器中:

- (void)viewDidLoad { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(showSecondVC:) name:@"showSecondVC" object:nil]; }

- (void)showSecondVC:(NSNotification)notification { // present second view controller here. }

按钮操作/完成:

[[NSNotificationCenter defaultCenter] postNotificationName:@"showSecondVC" object:nil userInfo:nil];

相关问题