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];
}
您是否在视图中添加了按钮?