Events UIViewController子类中的UIButton不响应任何触摸
几天前我遇到了这个问题,我也到处搜索解决方案,但没有一个能很好地工作。我在自定义viewController(UIViewController的子类)中添加了一个按钮,然后将自定义视图添加到myMainViewController中。 代码如下:Events UIViewController子类中的UIButton不响应任何触摸,events,uibutton,subclass,touches,Events,Uibutton,Subclass,Touches,几天前我遇到了这个问题,我也到处搜索解决方案,但没有一个能很好地工作。我在自定义viewController(UIViewController的子类)中添加了一个按钮,然后将自定义视图添加到myMainViewController中。 代码如下: customView.h cusomView:UIViewController { UIButton *myButton; } -(void)doSomething:(id)sender; customView.m -(void)viewDidLo
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