ios - ( swift )初始 View Controller 调用 TableView Controller 而不点击任何按钮

标签 ios swift

我尝试使用以下代码来做到这一点。然而,它不起作用。

警告:尝试呈现不在窗口层次结构中的 View !

有没有办法在不点击按钮的情况下调用其他 View Controller ?

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)
}

最佳答案

尝试移动

let secondViewController:UIViewController = OurTableViewController()
self.presentViewController(secondViewController, animated: true, completion: nil)

像这样查看DidAppear

override func viewDidAppear(animated: Bool) {
    let secondViewController:UIViewController = OurTableViewController()
    self.presentViewController(secondViewController, animated: true, completion: nil)
}

关于ios - ( swift )初始 View Controller 调用 TableView Controller 而不点击任何按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37403676/

相关文章:

ios - 旋转变换后调整 UIView 的大小

ios - 如何使类中的初始化方法等待 Firestore 在 Swift 4 中完成?

iOS10 - ContentView 阻止触摸 UITableView header 中的 UIButton

ios - 如何解决这个边界问题

ios - 将 NSPredicate 应用于 [(String, Array<String>)]

ios - AVAudioSession 的 Swift 子类在运行时不起作用

ios - 如何将派生类方法委托(delegate)给协议(protocol)方法?

iphone - 如何复制 iPhone 的 wifi 网络选择弹出 View

ios - 如何运行调用目录扩展?

iphone - 使用核心数据和 ARC 进行简单的内存管理