티스토리 뷰

Mobile/iOS

[iOS]UIWebView

out of coding 2016. 3. 8. 18:01

WebView를 사용하여서 화면에 페이지를 보여주는 방법이다.


* URL을 이용하는 방법

        NSURL* url = [NSURL URLWithString:@"http://www.apple.com"];

        NSURLRequest* urlRequest = [NSURLRequest requestWithURL:url];

        

        webView.delegate = self;

        [webView loadRequest:urlRequest];

     

* String을 이용하는 방법

        NSString* webString = @"<html><body><h1>Hello world!</h1></body></html>";


webView.delegate = self;

        [webView loadHTMLString:webString baseURL:[NSURL URLWithString:@"file:///."]];


* delegate 사용

<UIWebViewDelegate> 선언


- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {

            NSString* requestUrl = [[request URL] absoluteString];

            NSLog(@"webView: shouldStartLoadWithRequest:%@ navigationType:%ld", requestUrl, (long)navigationType);

            return YES;

}


- (void)webViewDidStartLoad:(UIWebView *)webView {

            NSLog(@"webViewDidStartLoad : %@", [[webView.request URL] absoluteString]);

}


- (void)webViewDidFinishLoad:(UIWebView *)webView {

            NSLog(@"webViewDidFinishLoad : %@", [[webView.request URL] absoluteString]);

}


- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {

    

}

댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2025/01   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함