Iphone 多个UIButton打开相同的视图但不同的内容

Iphone 多个UIButton打开相同的视图但不同的内容,iphone,ios,uiwebview,uibutton,xcode4.2,Iphone,Ios,Uiwebview,Uibutton,Xcode4.2,我正在寻找一种更快的方法来构建我的应用程序。由于我有一系列按钮,它们都将打开UIWebView。但每个按钮都会指向不同的网站 我可以知道我是否可以只制作一个xib文件?还是应该为每个按钮创建一个新文件 这是我转到下一个xib的代码 - (IBAction)items:(id)sender { //toggle the correct view to be visible Chelseapic *myView1 =[[Chelseapic alloc] initW

我正在寻找一种更快的方法来构建我的应用程序。由于我有一系列按钮,它们都将打开UIWebView。但每个按钮都会指向不同的网站

我可以知道我是否可以只制作一个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];

}

非常感谢

如果您想在笔尖中放置一组固定的按钮,请尝试为每个按钮制作一个单独的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.

您需要为
Chelseapic
提供它在
viewDidLoad
中使用的
url
属性,而不是在那里硬编码url。

谢谢您的帮助。这是工作,节省了我很多时间。