我是新來的IOS和目標C. 該場景是我有2個按鈕,它打開(與segue)2視圖控制器包含一個UIWebview。 我認爲最好用1個UIWebView來做,所以我試圖傳遞webvew的請求對象,並只使用一個webview控制器。使用prepareForSegue傳遞一個UIWebView請求
所以我得到了wwwBtn(UIButton打開一個網站)和fbBtn(UIButton去Facebook的URL)我的viewController和wwwWebViewController其中包含th UIWebView。
這是我做到的。
的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 *[email protected]"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];
}
我知道這是一個非常古老的問題,但如果我的代碼幫助你,如果你接受答案會很高興。 – Ashoor 2013-10-29 08:11:59