Ios 在swift 3中启动应用程序时,如何在另一个ViewController中预加载UIWebView?

Ios 在swift 3中启动应用程序时,如何在另一个ViewController中预加载UIWebView?,ios,swift3,webview,uiwebview,Ios,Swift3,Webview,Uiwebview,实际上,我在iOS应用程序中使用了两个Web视图。启动应用程序时,我想在SecondViewController中预加载第二个WebView。我尝试使用NSNotification Center预加载WebView,但它不起作用。如何在SecondViewController中预加载WebView 我用以下方法解决了类似的问题: 预加载包含webview的视图控制器,并将引用存储在Appdelegate中 在AppDelegate中调用self.preload.vc?.view.layoutSu

实际上,我在iOS应用程序中使用了两个Web视图。启动应用程序时,我想在SecondViewController中预加载第二个WebView。我尝试使用NSNotification Center预加载WebView,但它不起作用。如何在SecondViewController中预加载WebView

我用以下方法解决了类似的问题:

  • 预加载包含webview的视图控制器,并将引用存储在Appdelegate中
  • 在AppDelegate中调用self.preload.vc?.view.layoutSubviews()
  • 在任何需要的时候,你都可以展示它
  • 似乎有必要在视图控制器中以编程方式创建web视图

    class AppDelegate: UIResponder, UIApplicationDelegate {
    
    var window: UIWindow?
    
    //
    var preloadvc : PreloadVC? = nil
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
                //Preloading
            DispatchQueue.main.async(execute: {
                        self.preloadvc = PreloadVC()
                        //Thats the trick for preloading the view
                        self.preloadvc?.view.layoutSubviews()
                    })
        return true
    }
    
    }

    }

    在任何地方进行演示:

    @IBAction func ShowPreloaded(_ sender: Any) {
        let appDelegate = UIApplication.shared.delegate as! AppDelegate
        if let preloadedvc = appDelegate.preloadvc {
            self.present(preloadedvc, animated: true, completion: nil)
        }
    }
    

    我通过以下方式解决了类似的问题:

  • 预加载包含webview的视图控制器,并将引用存储在Appdelegate中
  • 在AppDelegate中调用self.preload.vc?.view.layoutSubviews()
  • 在任何需要的时候,你都可以展示它
  • 似乎有必要在视图控制器中以编程方式创建web视图

    class AppDelegate: UIResponder, UIApplicationDelegate {
    
    var window: UIWindow?
    
    //
    var preloadvc : PreloadVC? = nil
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
                //Preloading
            DispatchQueue.main.async(execute: {
                        self.preloadvc = PreloadVC()
                        //Thats the trick for preloading the view
                        self.preloadvc?.view.layoutSubviews()
                    })
        return true
    }
    
    }

    }

    在任何地方进行演示:

    @IBAction func ShowPreloaded(_ sender: Any) {
        let appDelegate = UIApplication.shared.delegate as! AppDelegate
        if let preloadedvc = appDelegate.preloadvc {
            self.present(preloadedvc, animated: true, completion: nil)
        }
    }