当我在我的 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/