views:

34

answers:

2

I have a UIWebView on my main window. Can I control that via my second view controller? If so could you give me an example?

+2  A: 

Yes you can. The "how" is a basic Cocoa / application architecture subject you can learn from the introductory documentation from Apple or any number of other web sites.

The gist is that you need to have a reference to the web view's controller (or the web view itself) from the second controller. This could be an outlet or a regular instance variable in the second controller. Then it's a matter of calling [firstController makeTheWebViewDoSomething];.

See also Communicating with Objects.

Joshua Nozzi
Ahh man thats perfect :)
A: 

If you have a "parent" view that owns both the WebView and the other subview from which you want to control.

In the "second view" create a member variable (assign @property and @synthesize, too):

  MyUIViewController *parent

After creating the "second" view, call:

  [[self secondview] setParent:self];

Now from the second view, to do something to the WebView, do whatever you want, like:

  [[parent webview] goback];
Brad