简体   繁体   English

如何向一个UIView控件中的一个动态按钮添加操作以移回UIViewController

[英]How to add action to one dynamic button in one UIView Control to move back to UIViewController

在我的应用程序中,我使用UIViewController并动态创建了UIView。在该视图中动态创建了子视图(UIButton和PickerViewController)。我想在UIViewController的标签控件中显示选定的选择器视图值。移回UIViewController ...

You can either pass the reference of the UIViewCOntroller to the subview or you can create delegate methods for the subview. 您可以将UIViewCOntroller的引用传递给子视图,也可以为子视图创建委托方法。

Method 1 : 方法1:

//below code is written in your UIViewController //下面的代码写在你的UIViewController中

/*You should write the implementation of initWithFrame:viewController: in UIVIEW / *您应该在UIVIEW中编写initWithFrame:viewController:的实现

CustomUIView *youSubView = [[CustomUIView alloc]initWithFrame : yourFrame viewController:self];

//below code is in CustomUIView

- (id) initWithFrame :(CGRect)frame viewController:(id)vc
{
....
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
[btn addTarget:vc action:methodinVc forControlEvents:UIControlEventTouchUpInside]; 

}

Method 2 : 方法2:

Make protocol and delegate in UIView and make the UIViewController to respond to the delegate calls 在UIView中创建协议和委托,并使UIViewController响应委托调用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM