我正在尝试创建一个自定义 UIView,我们称之为FooView。
FooView.h
#import <UIKit/UIKit.h>
@interface FooView : UIView
@property (nonatomic, strong) UITextField *barTextField;
@property (nonatomic, strong) UIButton *submitButton;
@end
FooView.m
#import "FooView.h"
@implementation FooView
@synthesize barTextField = _barTextField;
@synthesize submitButton = _submitButton;
...
@end
FooViewController.h
#import <UIKit/UIKit.h>
#import "FooView.h"
@interface FooViewController : UIViewController
@property (nonatomic, strong) FooView *fooView;
@end
FooViewController.m
#import "SearchViewController.h"
@interface SearchViewController ()
@end
@implementation SearchViewController
@synthesize fooView = _fooView;
@end
我想在FooViewController中实现按钮触摸事件,delegate
可以实现吗?如果是,如何?
目前,我正在以这种方式添加触摸事件
FooViewController.m
- (void)viewDidLoad
{
[self.fooView.submitButton addTarget:self action:@selector(submitTapped:) forControlEvents:UIControlEventTouchUpInside];
}
...
- (IBAction)submitTapped
{
...
}
但我认为这不是一个好的解决方案,因此需要一些专家建议。
任何的想法?