0

嘿伙计们,我正在尝试让我的项目上的按钮打开一个不同的webview url. 我是 iOS 编程新手,但我使用过 Android 编程。这可能吗?我已经准备好创建webview位于支持文件文件夹中的另一个视图。

这是我下面的代码

视图控制器.m

#import "ViewController.h"

@implementation ViewController

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

-(void)viewDidLoad
{
    NSString *urlString = @"http://www.athletic-profile.com/Application";

    //Create a URL object.
    NSURL *url = [NSURL URLWithString:urlString];

    //URL Requst Object
    NSURLRequest *webRequest = [NSURLRequest requestWithURL:url];

    //Load the request in the UIWebView.
    [webView loadRequest:webRequest];
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
}

- (void)viewDidDisappear:(BOOL)animated
{
    [super viewDidDisappear:animated];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
@synthesize webView;        
@end
4

2 回答 2

0

Firstly you can drag & drop UIButton in First Class & create action of that Button then create a new class for UIWebView in which you want to open you url named your choice which is subclass of UIViewController then into your .Xib or Storyboard you just drag & drop the UIWebView then create outlet of UIWebView after you write this code in first class of that button's action :-

- (IBAction *) firstButton:(id) sender
    {
           NSString *urlString = @"http://www.athletic-profile.com/Application";

           //Create a URL object.
           NSURL *url = [NSURL URLWithString:urlString];

           //URL Request Object
           NSURLRequest *webRequest = [NSURLRequest requestWithURL:url];

           //Load the request in the UIWebView.
           [webView loadRequest:webRequest];
    }
于 2013-11-07T12:04:26.900 回答
0

向您的视图添加一个按钮,然后连接到它。在操作方法中只需编写您的代码

-(IBAction*)yourButtonActionMethod:(id)sender
{

       [UIWebView *aWebView =[[UIWebView alloc] initWithFrame:CGRectMake(x,y,width,height)];
       aWebView.delegate=nil;
       NSString *urlString = @"http://www.athletic-profile.com/Application";

       //Create a URL object.
       NSURL *url = [NSURL URLWithString:urlString];

       //URL Requst Object
       NSURLRequest *webRequest = [NSURLRequest requestWithURL:url];

       //Load the request in the UIWebView.
       [aWebView loadRequest:webRequest];
       [self.view addSubView:aWebView];
}
于 2013-11-07T04:15:37.560 回答