1 #import "MJViewController.h"2 3 @interfaceMjviewcontroller () <uisearchbardelegate, uiwebviewdelegate>4 5@property (Weak, nonatomic) iboutlet UIWebView *WebView;6@property (Weak, nonatomic) Iboutlet Uibarbuttonitem *Backbutton;7@property (Weak, nonatomic) Iboutlet Uibarbuttonitem *Forwarbutton;8 9 @endTen One @implementationMjviewcontroller A -- (void) Viewdidload - { the [Super Viewdidload]; - -[Self loadString:@"http://m.baidu.com"]; - } + - //let the browser load the specified string and search using m.baidu.com +- (void) LoadString: (NSString *) Str A { at //1. URL location resource, address of resource required -NSString *urlstr =str; - if(! [Str hasprefix:@"/ http"]) { -URLSTR = [NSString stringWithFormat:@"http://m.baidu.com/s?word=%@", str]; - } - inNsurl *url =[Nsurl Urlwithstring:urlstr]; - to //2. Tell the URL to the server, request, request data from m.baidu.com +Nsurlrequest *request =[Nsurlrequest Requestwithurl:url]; - the //3. Send a request to the server * [Self.webview loadrequest:request]; $ }Panax Notoginseng - #pragmaMark-Search Bar Agent the //Start Search +- (void) searchbarsearchbuttonclicked: (Uisearchbar *) Searchbar A { theNSLog (@"%@", searchbar.text); + [self loadString:searchBar.text]; - $ [Self.view Endediting:yes]; $ } - - //text Changes the- (void) Searchbar: (Uisearchbar *) Searchbar textdidchange: (NSString *) SearchText - {WuyiNSLog (@"SearchText-%@", SearchText); the } - Wu #pragmaMark-webview Proxy method - #pragmaMark finishes loading, page linked list data is updated About- (void) Webviewdidfinishload: (UIWebView *) WebView $ { - //determine the state of the button according to the current state of the WebView -self.backButton.enabled =Webview.cangoback; -self.forwarButton.enabled =Webview.cangoforward; A } + the @end
WebView (Simple browser)