在视图控制器中:
- (void)viewDidLoad
{
[super viewDidLoad];
NSArray *array = [[NSArray alloc]initWithObjects:@"title1",@"title2",@"title3", nil];
self.scrollTabControl = [[ScrollTabControl alloc]initWithViewControllers:array];
[self.view addSubview:self.scrollTabControl]; //add a view to ViewController}
@interface ScrollTabControl : UIView
- (id)initWithControllers:(NSArray *)controllers
{
if((self = [super init])) {
_viewControllers = viewControllers;
_tabControls = [[TabControl alloc] initWithControllers:viewControllers];
[self addSubview:_tabControls];//initialization tab controler,in it,set UIControlEventTouchUpInside of button,response selector
}
return self;
}
现在,问题是如果我直接在视图控制器中使用 [self addSubView:TabControl],选择器将正确实现。但是如果我 [self addSubView:ScrollTabControl],按钮事件不会触发选择器,选择器也没有响应。我该如何处理这种情况?