iOS Objective-C 如何在运行时获取一个对象?
巴扎黑
巴扎黑 2017-04-17 17:52:58
0
1
305

比如我有两个view,view1和view2,view2在view1中的一个container里。

当显示viw1时,view2也是同时显示的。

当程序运行到view1时,我如何在view2的view controller中获取view1的对象呢?

实际上我是在view1中有一个操作,需要view2(tableview)来更新数据,所以想要view2做view1的代理,这个时候需要在view2中获取正在运行的view1对象。

巴扎黑
巴扎黑

reply all(1)
Peter_Zhu
  1. You can set a tag for the view, and then use viewWithTag to search when needed - this is not recommended, it is too obscure, error-prone, and the search efficiency is not high.

  2. If you need to access a view in the controller, you should connect it out and save a reference in the controller - normally this is what you should do.

  3. According to your needs, it is not appropriate to let view2 be the proxy of view1. View should only be responsible for displaying and accepting user operations. What subsequent actions are required after the operation is completed should be the responsibility of the controller, or you can use MVVM, view Bound to the viewModel, when the user performs any operation, the corresponding viewModel is updated, and the view on the other side monitors the changes in the viewModel and responds accordingly.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template