几天前我遇到了这个问题,我也到处搜索解决方案,但没有一个工作正常。我在自定义viewController(是UIViewController的子类)中添加了一个按钮,然后,将customView添加到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];
}
就这样,它显示得很好,但是按钮不响应任何触摸。你能帮我吗?谢谢。