I am trying to pass a String from an IBAction in my DetailsViewController to the viewDidLoad in my WebViewController to call up a URL in the WebView.
Does anybody know how I can do this?
My Code:
// DetailsViewController.m
- (IBAction)edu1Link:(id)sender {
NSString *webURL = [[NSString webURL] initWithString:@"http://www.apple.com"];
_webViewController = [[WebViewController alloc]
initWithNibName:@"WebViewController" bundle:nil];
[[self navigationController] presentModalViewController:_webViewController animated:YES];
}
// WebViewController.m
- (void)viewDidLoad
{
[_webView loadRequest:[NSURLRequ开发者_StackOverflowest requestWithURL:[NSURL URLWithString:webURL]]];
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
You could declare a property in your WebViewController
and set that property in the action before presenting the view controller.
I guess the best way would be to use a delegate methode here is a tutorial how you would do that
What albertamg is referring to is Objective-C properties. They are very powerful. Take a peak here: http://cocoacast.com/?q=node/103
Properties are like instance fields in Java. They're helpful in side-stepping zero-parameter-methods.
精彩评论