Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 使用按钮打开Web视图_Ios_Objective C - Fatal编程技术网

Ios 使用按钮打开Web视图

Ios 使用按钮打开Web视图,ios,objective-c,Ios,Objective C,嘿,伙计们,我正在尝试在我的项目上设置按钮,以打开一个不同的webview url。我不熟悉iOS编程,但我使用过andriod编程。这可能吗?我已经在supporting files文件夹中创建了另一个webview视图 下面是我的代码 Viewcontroller.m #import "ViewController.h" @implementation ViewController - (void)didReceiveMemoryWarning { [super didRecei

嘿,伙计们,我正在尝试在我的项目上设置按钮,以打开一个不同的
webview url
。我不熟悉iOS编程,但我使用过andriod编程。这可能吗?我已经在supporting files文件夹中创建了另一个
webview
视图

下面是我的代码

Viewcontroller.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

在视图中添加一个按钮,然后给它一个连接。在action方法中,只需编写代码

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

首先,您可以在第一个类中拖放UIButton并创建该按钮的操作,然后为UIWebView创建一个新类,在该类中,您希望打开名为“您的选择”的url,该url是UIViewController的子类,然后进入您的.Xib或故事板。您只需拖放UIWebView,然后在编写此代码后创建UIWebView的出口该按钮动作的第一类:-

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

您是否在视图中添加了按钮?