Webpage view control webview: code is directly used for webpage view controls, because you have written precautions for using the controls in the code.
Viewcontroller. h
@interface ViewController : UIViewController <UIWebViewDelegate>{ IBOutlet UITextField * myTextFiedld; IBOutlet UIWebView * myWebView;}@property (nonatomic,retain)UITextField * myTextFiedld;@property (nonatomic,retain)UIWebView * myWebView;-(IBAction)changeLocation:(id)sender;@end
Viewcontroller. m
@ Implementation viewcontroller @ synthesize mytextfiedld; @ synthesize mywebview; // button click event-(ibaction) changelocation :( ID) sender {mywebview. delegate = self; // Note: You must set the delegate [mytextfiedld resignfirstresponder]; // discard the first responder // build the URL object nsurl * url = [nsurl urlwithstring through the input text: mytextfiedld. text]; // construct the response object nsurlrequest * Req = [nsurlrequest requestwithurl: url] through the URL object; // pass the response object to [mywebview loadrequest: req] in the Web View;} // The browser load completion event-(void) webviewdidfinishload :( uiwebview *) webview {nslog (@ "finsh... "); // This method can execute a Javascript script nsstring * s = [mywebview stringbyevaluatingjavascriptfromstring: @" document.doc umentelement. textcontent "]; nslog (@" % @ ", S) ;}// events that fail to load the browser-(void) webview :( uiwebview *) webview didfailloadwitherror :( nserror *) error {nslog (@ "error... "); // nserror objects will be used frequently in the future and are very useful. Nslog (@ "% @", [error description]);}-(void) viewdidload {[Super viewdidload]; // do any additional setup after loading the view, typically from a nib .} -(void) didreceivememorywarning {[Super didreceivemorywarning]; // dispose of any resources that can be recreated .} -(void) dealloc {[mytextfiedld release]; [mywebview release]; [Super dealloc];} @ end
Note: The method of the control
Code Implementation
Source code of Baidu printed by calling Javascript in the background