【问题标题】:UIButton in a subClass of UIViewController not respond to any touchesUIViewController 子类中的 UIButton 不响应任何触摸
【发布时间】:2013-01-24 03:12:06
【问题描述】:

几天前我遇到了这个问题,我也到处搜索解决方案,但都没有正常工作。我在自定义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];
}

就这样,它显示得很好,但是按钮不响应任何触摸。你能帮帮我吗?谢谢。

【问题讨论】:

    标签: events uibutton subclass touches


    【解决方案1】:

    您不直接将 uibutton 添加到 myMainController 是否有原因?

    【讨论】:

      猜你喜欢
      • 2016-12-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-15
      • 1970-01-01
      • 1970-01-01
      • 2012-11-12
      • 2011-04-18
      相关资源
      最近更新 更多