获取子视图包含视图
问题描述:
如果我有,我已经添加子视图的视图(mainView
)。我如何得到subview实例到mainView?获取子视图包含视图
我对那些按应调用MAINVIEW的方法时,子视图按钮,所以我尝试:
[myButton addTarget:self.presentingViewController
action:@selector(myMethod:)
forControlerEvents:UIControletcetc];
和
[myButton addTarget:self.parentViewController action:@selector....];
,我读了parentViewController
现在在iOS 5中返回nil
但presentingViewController
似乎并没有这样做,因为它不是模态呈现的方式。它只是一个子视图。任何提示?
答
这种感觉,我认为你试图让你的看法知道超出其范围的对象。
如果您需要向任何包含您的视图的人通知事件,可以使用代表来完成此操作。
说:
@protocol YourClassDelegate
@optional
- (void)instanceOfYourClass:(YourClass *)instance tappedButton:(UIButton *)button;
@end
然后
@interface YourClass
@property (nonatomic, assign) id<YourClassDelegate> delegate;
@end
我希望你可以把它从这里,通过合成的财产,分配代表和调用方法时,你需要。
其实,这些subViews是mainView中的插座 – lascort 2012-01-02 13:51:29