import UIKit
import WebKit
class ViewController: UIViewController, WKUIDelegate, UITextFieldDelegate {
@IBOutlet var error: UILabel!
@IBOutlet var textoutlet: UITextField!
@IBAction func getweather(_ sender: Any) {
if introducirtex.text == ""
{
error.text = "try again"
}
else
{
error.text = "correct"
**dont know what to put here**
}
}
@IBOutlet var webdisplay: WKWebView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func viewDidAppear(_ animated: Bool) {
super .viewDidAppear(animated)
let url = URL(string: "https://www.google.com.mx/search?ei=wbZ4WtKGKsKE0wLLg4bQAg&q=" + textoutlet.text! + "+clima&oq=orizaba+clima&gs_l=psy-ab.3..35i39k1l2j0l8.58322.60729.0.60880.14.9.0.0.0.0.356.1191.2-2j2.4.0....0...1c.1.64.psy-ab..10.4.1190...0i20i263k1.0.ZfKggraKRyY")!
let urlrequest:URLRequest = URLRequest(url: url)
webdisplay.load(urlrequest)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
self.view.endEditing(true)
}
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
textField.resignFirstResponder()
return true
}
}
i want to click my getweather button when the user introduce in the textoutlet.text the city to get weather but i have no idea how to do it, i try to put the code on the else sentence and didnt work i dont know what to do im new plz help
Aucun commentaire:
Enregistrer un commentaire