Итак, у меня есть 2 вида: один - wkwebview, а другой - вид aboutus. В wkwebview у меня есть кнопка, которая переходит к представлению aboutus, чтобы пользователи могли читать о нас. Тем не менее, когда они возвращаются обратно на страницу, вся страница обновляется, как я могу предотвратить это? Я пытался проверить segue.identifier, но это тоже не сработало.
override func viewDidLoad() {
super.viewDidLoad()
let screenSize: CGRect = UIScreen.main.bounds
imageViewObject = UIImageView(frame:CGRect(x:0,y: 0, width: screenSize.width, height: screenSize.height))
imageViewObject.image = UIImage(named:"Image")
self.view.addSubview(imageViewObject)
webView.navigationDelegate = self
webView.isHidden = true
let myURL = URL(string: "https://www.google.com")
let myRequest = URLRequest(url: myURL!)
webView.configuration.preferences.javaScriptEnabled = true
webView.allowsBackForwardNavigationGestures = true
webView.load(myRequest)
}
override func viewDidAppear(_ animated: Bool)
{
self.view.addSubview(webView)
}
//this is what i tried but does not work
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "about_us_view"
{
webView.stopLoading();
}
}
aboutusviewcontroller
import UIKit
class AboutUsViewController: UIViewController {
var back_button: UIButton!
var btmbar : UIImageView!
var logo : UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
//let screenSize: CGRect = UIScreen.main.bounds
back_button = UIButton(type: .custom)
back_button.setImage(UIImage(named: "ic_ako_back_inactive"), for: .normal)
back_button.frame = CGRect(x: 0, y: screenHeight - 50, width: 50, height: 50)
back_button.addTarget(self, action: #selector(self.backButtonObj(_:)), for: .touchUpInside)
back_button.isHidden = false
btmbar = UIImageView(frame:CGRect(x:0 ,y: screenHeight-50, width:screenWidth, height: 80))
btmbar.image = UIImage(named: "btm_background_bar")
// Do any additional setup after loading the view.
}
override func viewDidAppear(_ animated: Bool)
{
self.view.addSubview(btmbar)
self.view.addSubview(back_button)
}
@objc func backButtonObj(_ sender: UIButton){ //<- needs `@objc`
performSegue(withIdentifier: "about_us_view", sender: self)
}
public var screenWidth: CGFloat {
return UIScreen.main.bounds.width
}
// Screen height.
public var screenHeight: CGFloat {
return UIScreen.main.bounds.height
}
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Get the new view controller using segue.destination.
// Pass the selected object to the new view controller.
}
*/
}