您可以執行它在應用程序的生命週期,一旦指揮的WebView代碼或相應定製。
// if you are navigating your application using navigation controller enables you to come back to the rootview without executing whole code of that class associated with view.
// this doesn't apply the whole life cycle of view controller
[self.navigationController pushViewController:vc animated:YES];
// if you navigating through below code this apply the whole life cycle concept of view controller.
[self presentViewController:vc animated:NO completion:nil];
你必須看看關於此視圖控制器的生命週期是一個有用的apple doc
的viewController生命週期短信
viewDidLoad中 - 被叫當你創建類並從xib加載時。非常適合初始設置和一次性工作。
ViewWillAppear - 在您的視圖出現之前調用,適用於在視圖可見之前隱藏/顯示字段或您希望每次發生的任何操作。因爲您可能會在視圖之間來回切換,所以每當您的視圖即將出現在屏幕上時都會調用此視圖。
ViewDidAppear - 在視圖出現後調用 - 啓動動畫或從API加載外部數據的好地方。
ViewWillDisappear/DidDisappear - 相同的思路viewWillAppear中/ ViewDidAppear。
ViewDidUnload/ViewDidDispose - 在Objective C中,這是您清理和發佈內容的地方,但這是自動處理的,因此您並不需要在此處執行很多操作。
當您更改視圖控制器時,您是否銷燬了您的webview? –
在webview中顯示你正在加載html coten的代碼 – rptwsthi
webView.loadHTMLString(htmlData,baseURL:nil) –