본문 바로가기

옛글/아이폰 프로그래밍

[iOS프로그래밍] UIWebview로 url을 띄워보기

반응형

[iOS프로그래밍] UIWebview로 url을 띄워보기

오오, 오늘 아시는 분과 함꼐 스터디를 하면서 많은 부분을 깨우쳤네요. 

자바에 아직도 생각이 묶여있어, X Code 환경이 매우 잘되어 있어 깜짝 놀라면서도, 아직은 익숙치가 않아 적응하려고 열심히 하고 있습니다. 안드로이드용 "전생에 우리는"을 아이폰용으로 제작중이며, 그에 관련해서 여러가지 부분들을 부분적으로 포스팅하려고 생각중입니다. 꽤나 매력있는 언어임은 틀림없네요 ^^ 푹빠져서 공부중입니다~!


이번 포스팅은 UIWebview 를 통해 URL 을 불러오는 부분입니다. 

참고 URL은 http://conecode.com/news/2011/05/ios-tutorial-creating-a-web-view-uiwebview/ 이며, 


10. Add the following code.

- (void)viewDidLoad {
[super viewDidLoad];
NSString *fullURL = @"http://conecode.com"; 
NSURL *url = [NSURL URLWithString:fullURL]; 
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url]; 
[webView loadRequest:requestObj];

}

 

NSString *fullURL = @”http://conecode.com”; We’re making a string called fullURL and setting it to the website we want our web view to load. But right now, the program thinks it’s just a bunch of text. (note the @ symbol before the quotes. You need this any time you’re setting a string with quotes.)

NSURL *url = [NSURL URLWithString:fullURL]; This tells the program that the text is actually a web address, or URL. It is now a URL object called url.

NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];This tells the program what we’re going to do with the URL object. We’re going to request the URL. It is now a request object called requestObj.

[webView loadRequest:requestObj]; Finally, we’re going to load the request into our Web View that we called webView earlier.

That’s all the coding there is. Now to prepare our interface (xib) file.



위와 같은 방법을 거치면됩니다. 각 부분에 대해 나뉘는 부분은 자바와는 조금 다른부분이네요. 
자바의 경우에는, URL 을 따로 변수선언하고, WebClient 혹은 CustomeWebClient 를 만들어서 연결해서 띄우는데, 신기하네요 ~! 



반응형