开发者

How to create new view w/ webview from push of button

UPDATED QUESTION: Hello , so I was able to create the modal view curl up overlay for this use. However I now have the issue that I can click on the button1 and pull up second view with the url1 on webView1, but when I click button2 I receive the display of url1 on webview also. below is the code can you help me out on what I'm doing wrong?

FourthViewController.h has the following code:

'

#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 has the following code:

'

#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];
    [开发者_Python百科super dealloc];
}


@end

Where or how would I add the second url and have it distinguis on click of other buttons. Thank you in advance for the ongoing help.


Original Question: Hello,

So first app and I'm trying to make some basic function use of buttons, Im doing this in a tab bar application. On my fourth tab view a view opens with 3 buttons, on the click of the button I am trying to get a webpage to load within the app (i was able to successfully make the webpages open via safari on button touchup inside click, but that is not how I want it to load. So I edited the way it loads and on push of button the website is now opening within the webView. However I want to create this webview on a new view rather then on the same view where the 3 buttons are, but I'm not clear on how to do this. Any input would be greatly appreciated (I apologize beforehand since this seems as an easy task, but haven't figured it out yet, I did some searching before asking, but was unable to find anything that showed how to do this on push of different button to load webview on a new view within the same XIB.

Thanks.

Below is the code that I have for the load of webview on push of button.

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"]]];
}

Basically I'm trying to get different buttons to push to the same new view but the only difference is that i want the uiwebview to display a different URL depending on the button click that bring the new view.


As NWCoder mention, it depends how you like the new webview to be shown.

Display in UINavigationController-

  1. Make your fourth tab a uinavigationcontroller and set the 3 button view controller as the top most view controller.
  2. Create a new UIViewController that encapsulate the UIWebView.
  3. When user click on the open webview button, create and push the uiviewcontroller that contains the uiwebview

Display in modal view:

  1. Create a new UIViewController that encapsulate the UIWebView.
  2. When user click on the open webview button, create and push the webview uiviewcontroller by calling the fourth's tab uiviewcontroller presentModalViewController:animated.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜