我有一个 UIViewController
称为“MainViewController”,它使用自定义类“CustomController”来控制其中一个 subview 。自定义类实例化 UIButton
s 在代码中。如何让这些按钮触发 MainViewController 中的方法?
最佳答案
我认为代表团是去那里的方式。
CustomControllerDelegate
里面 CustomController.h
使用这样的方法,例如:- (void) customControllerButtonPressed(id)sender; // BTW: you can use `CustomController` instead of `id` if you make a forward declaration for this class
.m
中合成它文件@property (assign) id<CustomControllerDelgate> delegate;
[self.delegate customControllerButtonPressed:self];
MainViewController
您使其符合指定的协议(protocol)并像这样设置 CustomControllers 委托(delegate):CustomViewController *customVC = [[CustomViewController alloc] init];
customVC.delegate = self;
MainViewController
的指定方法的实现被调用。 关于iphone - 制作自定义类的按钮触发父类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9354517/