您基本上可以有一个viewController
和多个按钮,然后将这些按钮与它们的操作连接起来以打开相应的按钮URL
,您可以使用其他viewController
连接UIWebView
为 iboutlet 和 aUIButton
来关闭此 viewController 您必须在第二个 viewController 中为 webview实现UIWebViewDelegate
第一视图控制器.m
-(IBAction)button1Clicked:(id)sender{
self.myWebController=[[MyWebViewController alloc]initWithNibName:@"MyWebViewController" bundle:nil];
[self.myWebController setWebViewUL:@"http://www.google.com"];
[self presentViewController:self.myWebController animated:YES completion:nil];
}
-(IBAction)button2Clicked:(id)sender{
self.myWebController=[[MyWebViewController alloc]initWithNibName:@"MyWebViewController" bundle:nil];
[self.myWebController setWebViewUL:@"http://www.apple.com"];
[self presentViewController:self.myWebController animated:YES completion:nil];
}
-(IBAction)button3Clicked:(id)sender{
self.myWebController=[[MyWebViewController alloc]initWithNibName:@"MyWebViewController" bundle:nil];
[self.myWebController setWebViewUL:@"http://www.yahoo.com"];
[self presentViewController:self.myWebController animated:YES completion:nil];
}
MyWebViewController.m
@synthesize myWebView;
@synthesize strURL;
-(void)setWebViewUL:(NSString*)urlstr{
self.strURL=urlstr;
}
- (void)viewDidLoad
{
[self loadURLinWebView:self.strURL];
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
-(void)loadURLinWebView:(NSString*)urlStr {
NSURLRequest *request=[NSURLRequest requestWithURL:[NSURL URLWithString:urlStr] cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData timeoutInterval:30.0f];
[myWebView loadRequest:request];
}
-(IBAction)buttonDismisClicked:(id)sender{
[self dismissViewControllerAnimated:YES completion:nil];
}
// delegate methods
-(void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error{
}
-(void)webViewDidFinishLoad:(UIWebView *)webView{
}
-(void)webViewDidStartLoad:(UIWebView *)webView{
}