【发布时间】:2012-02-06 04:05:45
【问题描述】:
我是 IOS 和 Objective C 的新手。 场景是我有 2 个按钮,它们打开(使用 segue)2 个包含 UIWebview 的视图控制器。 我认为使用 1 个 UIWebView 会更好,所以我尝试传递 webvew 的请求对象并仅使用一个 webview 控制器。
所以我得到了 wwwBtn(打开网站的 UIButton)和 fbBtn(转到 Facebook URL 的 UIButton)我的 viewController 和包含 UIWebView 的 wwwWebViewController。
这就是我的做法。
viewController.h 文件:
@interface ViewController : UIViewController {
UIButton *wwwBtn;
UIButton *fbButton;
}
@property (retain, nonatomic) IBOutlet UIButton *wwwBtn;
@property (retain, nonatomic) IBOutlet UIButton *fbBtn;
ViewController.m 文件:
#import "ViewController.h"
#import "wwwWebViewController.h"
@implementation ViewController
@synthesize wwwBtn;
@synthesize fbBtn;
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"web"]) {
NSString *urlstr=@"http ://www.google.com";
wwwWebViewController *vc = [segue destinationViewController];
vc.urlStr = urlstr;
} else if ([[segue identifier] isEqualToString:@"fb"]) {
NSString *urlstr = @"http://www.facebook.com";
wwwWebViewController *vc = [segue destinationViewController];
vc.urlStr = urlstr;
}
}
wwwWebViewController.h 文件:
@interface wwwWebViewController : UIViewController {
UIWebView *webView;
}
@property (retain, nonatomic) IBOutlet UIWebView *webView;
wwwWebViewController.m 文件:
- (void)viewDidLoad
{
NSURL *url = [NSURL URLWithString:urlStr];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[webView loadRequest:requestObj];
[super viewDidLoad];
}
【问题讨论】:
-
我知道这是一个非常古老的问题,但如果我的代码对您有所帮助,如果您接受答案将很高兴。