'Xcode WebView'에 해당되는 글 1건

  1. 2012.07.18 아이폰 WebView 만들기 예제 따라하기
C/Objective C/ios2012.07.18 11:36

- 아이폰의 WebView를 이용하여, 인터넷 창을 띄울수 있다.

- 이를 활용하여 하이브리드 앱을 만들 수 있다.


- 화면 디자인

- WebView 만들기 순 서

1. Xcode 실행
2. Single View Application
3. Project Name : “WebViewTest”
4. storyboard에 Web View 위치
5. Assistant Editor로 Web View 드래그 6. “myWebView” 입력
7. ViewController.m 파일에 입력

-(void)viewDidLoad {

[super viewDidLoad];

NSURL *myURL = [NSURL URLWithString:@“http://www.naver.com”]; NSURLRequest *myURLReq = [NSURLRequest requestWithURL: myURL]; [myWebView loadRequest:myURLReq];

}

page5image7168

8. 실행 


- ViewController.m 소스코드


#import "ViewController.h"


@interface ViewController ()


@end


@implementation ViewController

@synthesize myWebView;

@synthesize myTextField;

@synthesize myGo;

@synthesize myBack;


- (void)viewDidLoad

{

    [super viewDidLoad];

// Do any additional setup after loading the view, typically from a nib.

NSURL *myURL = [NSURL URLWithString:@"http://www.naver.com"];

NSURLRequest *myURLReq = [NSURLRequest requestWithURL:myURL];

[myWebView loadRequest:myURLReq];

}


- (void)viewDidUnload

{

    [self setMyWebView:nil];

[self setMyTextField:nil];

[self setMyGo:nil];

[self setMyBack:nil];

    [super viewDidUnload];

    // Release any retained subviews of the main view.

}


- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation

{

if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {

    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);

} else {

    return YES;

}

}


- (IBAction)myButton:(id)sender {

if(sender == myGo){

NSURL *myURL = [NSURL URLWithString:myTextField.text];

NSURLRequest *myURLReq = [NSURLRequest requestWithURL:myURL];

[myWebView loadRequest:myURLReq];

[myTextField resignFirstResponder];

}

else if(sender == myBack)

[myTextField resignFirstResponder];

}

@end


- 실행 화면



신고
Posted by Namseungil