开发者

Access Subview in another ViewController?

ho开发者_运维知识库w can i access a subview i added in another view controller? Like

DummyViewController:

- Subview 1
- Subview 2

TestViewController:

- Subview 3

Now I want to access the properties of Subview 1 (DummyViewController) in Subview 3 (TestViewController).

Thank + Regards


Put or send the shared properties in another object above both dummyviewcontroller and testviewcontroller (the M of the MVC pattern) and pass a reference to that model object down to whoever needs those properties.

Or have whatever is above those two view controllers put a reference to the dummyviewcontroller into the testviewcontroller subview.


import "DummyViewController.h"

DummyViewController *dummy = [[DummyViewController alloc] init];

dummy.subview1.button.hidden = NO;

Here I am accessing the button of subview1 in testviewcontroller.

hope this works for u...


In "DummyViewController" in viewDidLoad

subView1.tag = 1;
subView2.tag = 2;

In TestViewController

DummyViewController *dummy = [[DummyViewController alloc] init];
UIView subview1 = [dummy.view viewWithTag:1];


The added sub views can be found in the properties of UIView.

property(nonatomic, readonly, copy) NSArray *subviews

But you need something else to distinguish what you want. You can assign tag property to the view, or distinguish by the class of the view.

The convenience method -viewWithTag: of UIView can help you find out the view with unique tag.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜