UIViewController 子类中的 UIButton 不响应任何触摸



我前几天遇到了这个问题,我也到处搜索了解决方案,但没有一个工作正常。我在自定义视图控制器(是UIViewController的子类)中添加了一个按钮,然后将自定义视图添加到myMainViewController中。像这样的代码:

customView.h
cusomView:UIViewController
{
UIButton *myButton;
}
-(void)doSomething:(id)sender;
customView.m
-(void)viewDidLoad
{
  [super viewDidLoad];
  self.view=[UIView alloc] initWithFrame:CGRectMake(0,100,100,100);
  //init the button....
  [myButton addTarget:self action:@selector(doSomething:)     forControlEvents:...upInside];
  [self.view addSubViews:myButton];
}
-(void)doSomething:(id)sender
{
.......
}

myMainViewController
-(void)viewDidLoad
{
   ......
   customView *cusView=[customView alloc] init];
   [self.view addSubViews:cusView];
}

正好,它显示得很好,但按钮不会反射到任何触摸。你能帮我吗?谢谢。

您没有理由不直接将 uibutton 添加到myMainController中?