我尝试使用以下代码执行此操作。但是,它不起作用。
警告:尝试显示其视图不在窗口层次结构中!
有没有办法在不按下按钮的情况下调用其他视图控制器?
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let configuration = WKWebViewConfiguration()
let controller = WKUserContentController()
controller.addScriptMessageHandler(self, name: "JSListener")
configuration.userContentController = controller
let webview = WKWebView(frame: self.view.frame, configuration: configuration)
let url = NSBundle.mainBundle().URLForResource("index1", withExtension: "html")
let request = NSURLRequest(URL: url!)
self.view = webview
webview.loadRequest(request)
let secondViewController:UIViewController = OurTableViewController()
self.presentViewController(secondViewController, animated: true, completion: nil)
}
答案 0 :(得分:0)
尝试移动
let secondViewController:UIViewController = OurTableViewController()
self.presentViewController(secondViewController, animated: true, completion: nil)
to viewDidAppear就像那样
override func viewDidAppear(animated: Bool) {
let secondViewController:UIViewController = OurTableViewController()
self.presentViewController(secondViewController, animated: true, completion: nil)
}