我有这个简单的应用程序我试图写,用户应该可以使用谷歌搜索找到图像,问题是当他用长按选择照片时,我是收到错误: 警告:尝试显示其视图不在窗口层次结构中!
如果我在ViewController中用self.navigationController!.presentViewController(nav, animated: true, completion: nil)
替换self.navigationController!.pushViewController(nav, animated: true)
,一切正常。这让我疯狂。
的AppDelegate:
let viewController = ViewController()
let navController = UINavigationController.init(rootViewController: viewController)
let frame = UIScreen.mainScreen().bounds
window = UIWindow.init(frame: frame)
window?.rootViewController = navController
window?.makeKeyAndVisible()
// Override point for customization after application launch.
return true
的ViewController:
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let search = UIBarButtonItem.init(barButtonSystemItem: .Search, target: self, action: Selector("searchImages"))
self.setToolbarItems([search], animated: false)
self.navigationController?.setToolbarHidden(false, animated: false)
}
func searchImages() {
let searchVC = SearchImageViewController()
let nav = UINavigationController.init(rootViewController: searchVC)
self.navigationController!.presentViewController(nav, animated: true, completion: nil)
}
最后是SearchImageViewController:
weak var webView: UIWebView?
override func loadView() {
let webView = UIWebView.init(frame: CGRectZero)
self.view = webView
self.webView = webView
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
let done = UIBarButtonItem.init(barButtonSystemItem: .Done, target: self, action: Selector("done"))
self.navigationItem.rightBarButtonItem = done
let url = NSURL.init(string: "http://images.google.com/ncr")
let request = NSURLRequest.init(URL: url!)
webView!.loadRequest(request)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func done() {
}
任何想法都将不胜感激。
顺便说一下,显示正常的AlertController工作正常(在done
函数内)。