WebView (Simple browser)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.