ios - How do I connect the search bar with the uiwebview in Xcode 6 using Swift? -
i'm kinda new coding swift , need help: how connect search bar web view when type search appears in google?
my code far:
import uikit class viewcontroller: uiviewcontroller { @iboutlet var webview: uiwebview! override func viewdidload() { super.viewdidload() allow url = nsurl(string: "http://google.com") allow request = nsurlrequest(url: url) webview.loadrequest(request) } override func didreceivememorywarning() { super.didreceivememorywarning() // dispose of resources can recreated. }
here basic example. type textfield: http://www.apple.com
import uikit import webkit class viewcontroller: uiviewcontroller, uitextfielddelegate { @iboutlet weak var webview: uiwebview! @iboutlet weak var textfield: uitextfield! @ibaction func go(sender: anyobject) { var text = textfield.text var url = nsurl(string: text) var req = nsurlrequest(url:url!) self.webview!.loadrequest(req) } override func viewdidload() { super.viewdidload() self.textfield.delegate = self } }
updated illustration showing uisearchbar
import uikit import webkit class viewcontroller: uiviewcontroller, uisearchbardelegate { @iboutlet weak var searchbar: uisearchbar! @iboutlet weak var webview: uiwebview! func searchbarsearchbuttonclicked(searchbar: uisearchbar!) { searchbar.resignfirstresponder() var text = searchbar.text var url = nsurl(string: text) //type "http://www.apple.com" var req = nsurlrequest(url:url!) self.webview!.loadrequest(req) } override func viewdidload() { super.viewdidload() self.searchbar.delegate = self } }
ios xcode swift uiwebview uisearchbar
No comments:
Post a Comment