Cross View Communication

别来无恙 提交于 2019-12-24 09:49:10

问题


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?


回答1:


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.




回答2:


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];


来源:https://stackoverflow.com/questions/4026372/cross-view-communication

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!