我几天前遇到过这个问题,我也到处搜索解决方案,但没有一个工作正常。我在自定义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];
}
就是这样,它显示得很好,但按钮没有响应任何触摸。你能帮助我吗?谢谢。
答案 0 :(得分:0)
你有没有理由不直接向myMainController
添加uibutton?