我正在尝试webViewController
使用该prepareForSegue
方法将数据传递给 a,如下所示:
-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if([segue.identifier isEqualToString:@"RBOM"])
{
WebViewController *destViewController = segue.destinationViewController;
destViewController.url = [NSURL URLWithString:@"https:myURL.com/Articles.asp?ID=274"];
}
if([segue.identifier isEqualToString:@"Home"])
{
WebViewController *destViewController = segue.destinationViewController;
destViewController.url = [NSURL URLWithString:@"http://www.myURL.com"];
}
}
这就是为什么我的webViewController
课程看起来像这样的原因:
#import "WebViewController.h"
@interface WebViewController ()
@end
@implementation WebViewController
@synthesize webView;
@synthesize url;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
[self.navigationController setNavigationBarHidden:NO];
self.title = @"MyURL.com";
self.webView.delegate = self;
NSLog(@"URL: %@", self.url); <---- This is null
NSURLRequest *requestURL = [NSURLRequest requestWithURL:url];
[self.webView loadRequest:requestURL];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
@end
这是webViewController.h
:
#import <UIKit/UIKit.h>
@interface WebViewController : UIViewController <UIWebViewDelegate>
@property (weak, nonatomic) IBOutlet UIWebView *webView;
@property (weak, nonatomic) NSURL *url;
@end
问题是我的 URL 为空。有人能告诉我为什么吗?