如何使用按下按钮创建带/ webview的新视图

时间:2011-03-14 19:06:11

标签: iphone xcode ios4 uiwebview interface-builder

更新的问题: 你好,所以我能够为这个用途创建模态视图curl up overlay。但是我现在遇到的问题是我可以点击button1并使用webView1上的url1拉出第二个视图,但是当我点击button2时,我也会在webview上收到url1的显示。下面是代码,你可以帮我解决我做错了什么吗?

FourthViewController.h具有以下代码:

#import <UIKit/UIKit.h>


@interface FourthViewController : UIViewController {
    UIButton *openBlogButton, *openFbButton, *openYelpButton;
}

@property (nonatomic, retain) IBOutlet UIButton *openBlogButton, *openFbButton, *openYelpButton;


-(IBAction)openBlog:(id)sender;
-(IBAction)openFacebook:(id)sender;
-(IBAction)openYelp:(id)sender;

@end

FourthViewController.m具有以下代码:

#import "FourthViewController.h"
#import "FourthBlogWebViewController.h"
#import "FourthFBWebViewController.h"


@implementation FourthViewController

@synthesize openBlogButton, openFbButton, openYelpButton; 

-(IBAction)openBlog:(id)sender {
    FourthBlogWebViewController *sampleView = [[[FourthBlogWebViewController alloc] init] autorelease];
    [sampleView setModalTransitionStyle:UIModalTransitionStylePartialCurl];
    [self presentModalViewController:sampleView animated:YES];
}

//THIS IS WHERE I THINK THE ISSUE IS, WHEN I CLICK openFacebook it should lead to the fb URL, it seems as if I should be able to list all possible urls on the first fourthwebviewcontroller, but i was not able to be successful so I tried making a second webview controller to feed it this url but this failed...lol. thnx for any input.
-(IBAction)openFacebook:(id)sender {
    FourthFBWebViewController *sampleView = [[[FourthFBWebViewController alloc] init] autorelease];
    [sampleView setModalTransitionStyle:UIModalTransitionStylePartialCurl];
    [self presentModalViewController:sampleView animated:YES];
}

-(IBAction)openYelp {
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.yelp.com"]];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

- (void)viewDidUnload {
    [super viewDidUnload];
}


- (void)dealloc {
    [openBlogButton release];
    [openFbButton release];
    [openYelpButton release];
    [super dealloc];
}


@end

FourthBlogWevViewController.h

#import <UIKit/UIKit.h>


@interface FourthBlogWebViewController : UIViewController {
    UIButton *dismissViewButton;
    IBOutlet UIWebView *webViewFB;
}

@property (nonatomic, retain) IBOutlet UIButton *dismissViewButton;
@property (nonatomic, retain) UIWebView *webViewFB;

- (IBAction)dismissView:(id)sender;

@end'

FourthBlogWebViewController.m code:

'#import "FourthBlogWebViewController.h"


@implementation FourthBlogWebViewController

@synthesize dismissViewButton, webViewFB;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
    }
    return self;
}

-(IBAction)dismissView:(id)sender {
    [self dismissModalViewControllerAnimated:YES];
}

- (void)viewDidLoad {
    NSString *urlAddress = @"http://www.facebook.com";  
    NSURL *url = [NSURL URLWithString:urlAddress];
    NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
    [webViewFB loadRequest:requestObj];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

- (void)viewDidUnload {
    [super viewDidUnload];
}


- (void)dealloc {
    [dismissViewButton release];
    [webViewFB release];
    [super dealloc];
}


@end

我在哪里或如何添加第二个网址,并在点击其他按钮时将其区分开来。提前感谢您的持续帮助。


原始问题: 你好,

所以第一个应用程序,我正在尝试使用按钮的一些基本功能,我在标签栏应用程序中这样做。在我的第四个标签视图上,一个视图打开,有3个按钮,点击按钮我试图在应用程序中加载一个网页(我能够成功地通过Safari点击内部按钮点击打开网页,但是不是我想要它加载的方式。所以我编辑了它加载的方式,按下按钮,网站现在在webView中打开。但是我想在新视图上创建这个webview而不是在同一个视图中3按钮是,但我不清楚如何做到这一点。任何输入都将非常感激(我事先道歉,因为这似乎是一个简单的任务,但还没有想出来,我做了一些搜索,然后问,但在推送不同的按钮以在同一个XIB中的新视图上加载webview时,无法找到任何显示如何执行此操作的内容。

感谢。

下面是按下按钮时加载webview的代码。

on fourthviewcontroller.h

#import <UIKit/UIKit.h>

@interface FourthViewController : UIViewController {
    IBOutlet UIWebView *webView;
}

-(IBAction)openWebsite:(id)sender;
-(IBAction)openButton2;
-(IBAction)openButton3;

@property (nonatomic, retain) UIWebView *webView;

@end

on fourthviewcontroller.m

#import "FourthViewController.h"

@implementation FourthViewController

@synthesize webView;

-(IBAction)openWebsite:(id)sender{
    [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.URL.com"]]];
}

-(IBAction)openButton2:(id)sender{
    [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.URL2.com"]]];
}

-(IBAction)openButton3:(id)sender{
    [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.URL3.com"]]];
}

基本上我正在尝试使用不同的按钮来推送到相同的新视图,但唯一的区别是我希望uiwebview根据带有新视图的按钮单击显示不同的URL。

1 个答案:

答案 0 :(得分:0)

正如NWCoder所说,这取决于您希望如何显示新的网页视图。

在UINavigationController-

中显示
  1. 将第四个选项卡设为uinavigationcontroller,并将3按钮视图控制器设置为最顶层的视图控制器。
  2. 创建一个封装UIWebView的新UIViewController。
  3. 当用户点击打开的webview按钮时,创建并推送包含uiwebview的uiviewcontroller
  4. 以模态视图显示:

    1. 创建一个封装UIWebView的新UIViewController。
    2. 当用户点击打开的webview按钮时,通过调用第四个选项卡uiviewcontroller presentModalViewController:animated来创建并推送webview uiviewcontroller。