2011-12-11 3 views
0

내 응용 프로그램을 작성하는 빠른 방법을 찾고 있는데요. 나는 일련의 버튼을 가지고 있기 때문에 UIWebView를 열 것이다. 그러나 각 버튼은 다른 웹 사이트로 이동합니다.여러 UIButton 동일한보기를하지만 다른 콘텐츠를 엽니 다

제가 xib 파일을 하나만 만들 수도 있습니다. 아니면 각 버튼에 대해 새 파일을 만들어야합니까?

다음 xib로 이동하는 코드입니다.

- (IBAction)items:(id)sender { 

     //toggle the correct view to be visible 
     Chelseapic *myView1 =[[Chelseapic alloc] initWithNibName:nil bundle:nil]; 
     [myView1 setModalTransitionStyle:UIModalTransitionStylePartialCurl]; 
     [self presentModalViewController:myView1 animated:YES]; 
    } 

그리고 이것은 WebView xib에서 URL을 여는 코드입니다.

- (void)viewDidLoad 
{  
    [super viewDidLoad]; 
    NSString *urlAddress = @"http://www.google.com" ; 
    NSURL *url = [NSURL URLWithString:urlAddress]; 
    NSURLRequest *requestObj = [NSURLRequest requestWithURL:url]; 
    [webView loadRequest:requestObj]; 
    [self.view addSubview:webView]; 

} 

많은 감사

답변

1

당신이 당신의 펜촉에 배치 할 버튼의 고정 세트가있는 경우, 각 버튼에 대해 별도의 IBAction를 제작하려고 :

// helper method 
- (void)presentViewControllerForURL:(NSURL *)url 
{ 
    Chelseapic *vc = [[Chelseapic alloc] initWithNibName:nil bundle:nil]; 
    vc.url = url; 
    [vc setModalTransitionStyle:UIModalTransitionStylePartialCurl]; 
    [self presentModalViewController:vc animated:YES]; 
} 

// Connect the first button in your nib to this action. 
- (IBAction)presentGoogle:(id)sender 
{ 
    [self presentViewControllerForURL:[NSURL URLWithString:@"http://www.google.com/"]]; 
} 

// Connect the second button in your nib to this action. 
- (IBAction)presentStackOverflow:(id)sender 
{ 
    [self presentViewControllerForURL:[NSURL URLWithString:@"http://stackoverflow.com/"]]; 
} 

// etc. 

당신은거야 거기에 URL을 하드 코딩하는 대신 Chelseapic 에서 사용하는 url 속성을 제공해야합니다.

+0

도움 주셔서 감사합니다. 그것은 일하고 있으며 많은 시간을 절약 해주었습니다. – Clarence

관련 문제