ios - swift - 警告 : attempt to present on whose view is not in the window hierarchy

标签 ios swift xcode6

当我在我的 SecondViewController 中点击后退按钮时,我遇到了这个问题。

2014-12-24 12:08:58.838 UPASS[5158:71438] Warning: Attempt to present <APPNAME.ThirdViewController: 0x7ae6bcc0> on <APPNAME.SecondViewController: 0x7af72060> whose view is not in the window hierarchy!

代码

import UIKit

class SecondViewController: UIViewController {

    @IBAction func btnSubmit(sender: AnyObject) {
        let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)

        let thirdViewController = storyBoard.instantiateViewControllerWithIdentifier("successView") as ThirdViewController
        self.presentViewController(thirdViewController, animated:true, completion:nil)
    }

    @IBAction func btnBack(sender: AnyObject) {
        let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)

        let firstViewController = storyBoard.instantiateViewControllerWithIdentifier("methodView") as FirstViewController
        self.presentViewController(firstViewController, animated:true, completion:nil)

    }

    override func viewDidLoad() {
        super.viewDidLoad()

        self.view.backgroundColor = UIColor(patternImage: UIImage(named: "bgCreateUser.jpg")!)
        // Do any additional setup after loading the view.
    }


}

最佳答案

btnBack 是否应该返回到较早的 View Controller ?如果是这样,不要呈现一个新的实例,而是使用以下方法返回到前一个实例:

dismissViewControllerAnimated(真,完成:无)

关于ios - swift - 警告 : attempt to present on whose view is not in the window hierarchy,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27631399/

相关文章:

ios - 如何创造橡皮筋效果?

swift - 具有返回类型的 swift 方法

xcode - Xcode插件停止工作

ios - 如何在 firebase 的节点中添加子节点

ios - 选择新单元格后,Xcode 仅记录先前选择的表格 View 单元格

iOS : How to get song id using echonest Api

authentication - 如何为 Split View Controller 创建启动页面

ios - ivar 的问题

ios - TableView 和 UIImageView 显示不正确的布局,除非滚动

swift - SwiftyJson 和 Alamofire 使用的解码结构