Reputation: 3164
Question: How do I perform custom initializations when using StoryBoards?
I have read several questions with the same keywords that are in my title, but could not find any answer. I beg your pardon if this question has already been asked or it is too basic: I have just started developing iOS apps.
Currently I have an application whose:
AppDelegate
reads from a source (currently a remote URL) two URLs that need to be displayed in instances of UIWebView
;TabBarController
with two tabs, that are instances of UIWebView
;UIWebView
have methods (init and setter) for receiving the URL of the file they need to display. These two UIWebView
display the URLs read by the AppDelegate
.I am trying to perform the same operations using a StoryBoard but do not know how to pass the URL
of the content to the two UIWebView
. I have read the answers concerning the initWithCoder
method, but cannot figure out how to pass the parameters.
Is there anyone who figured out what I meant in my (incredibly confused) question who is also able to help me?
Upvotes: 0
Views: 97
Reputation: 62062
On the general question of accessing references to view controllers in a tab bar controller...
A tab bar controller has a public property called viewControllers
, which is an array of view controllers which the tab bar controller contains.
You can access elements of this array just as you would any other array, but in this case, they're references to all your view controllers.
[tabBarController.viewControllers firstObject];
[tabBarController.viewControllers objectAtIndex:3];
for(UIViewController *vc in tabBarController.viewControllers) {
if([@"MyFirstVC" isEqualToString:vc.title]) {
// do stuff
}
}
etc. etc. etc.
Upvotes: 0
Reputation: 2547
I think the right place to do this is your ViewController. You should create an outlet of the UIWebView within your ViewController in order to be able to access them. Then to pass the URL to them you can use:
- (void)loadRequest:(NSURLRequest *)request
I don't understand why you read remotely the URLs in your AppDelegate but you can access your AppDelegate from your ViewController if needed as follows:
[[UIApplication sharedApplication] delegate]
Upvotes: 2