swift:视图不在视图层次结构中

时间:2016-04-05 08:03:15

标签: ios swift

我有一个homeView,它是应用启动时显示的初始视图。在其 viewWillAppear()方法中,我检查用户是否已登录。如果没有,则将其重定向到登录页面,如果他尚未注册,则他将成为针对注册页面。用户单击注册按钮时出现错误。 signUPView出现但它发出警告尝试在signupViewController上显示loginViewController,该视图不在窗口层次结构中。我在注册和登录视图之间显示了详细信息。 在提交uialert之后,我正在执行segue。 我有解决方案将代码放在viewDidAppear或ViewWillAppear方法中,但我按下按钮时会显示viewControllers。所以我不能使用这些方法。

我已经搜索了很多解决方案,但无法找到合适的解决方案。 请帮忙! 谢谢。

来自注册的触发代码:

                        dispatch_async(dispatch_get_main_queue()) {
                        if self.registerSuccess == true {


                            let alert = UIAlertController(title: "Registered!", message: "You have registered successfully!", preferredStyle: UIAlertControllerStyle.Alert)

                            alert.addAction(UIAlertAction(title: "OK", style: .Default, handler: { (action) -> Void in

                                self.dismissViewControllerAnimated(true, completion: nil)
                                self.nameTextField.text = ""
                                self.emailTextField.text = ""
                                self.passwordTextField.text = ""
                                self.performSegueWithIdentifier("loginSegue", sender: self)
                            }))

                            self.presentViewController(alert, animated: true, completion: nil)

                        } else {
                            let alert = UIAlertController(title: "Registration Failed!", message: "Please try again", preferredStyle: UIAlertControllerStyle.Alert)

                            alert.addAction(UIAlertAction(title: "OK", style: .Default, handler: { (action) -> Void in

                                self.dismissViewControllerAnimated(true, completion: nil)

                            }))

                            self.presentViewController(alert, animated: true, completion: nil)
                        }
                        }

screenshot of my storyboard

0 个答案:

没有答案