1

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?

petert
  • 6,672
  • 3
  • 38
  • 46
user393273
  • 1,430
  • 5
  • 25
  • 48

2 Answers2

3

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
  • 60,946
  • 14
  • 140
  • 135
0

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
  • 11,262
  • 8
  • 55
  • 74