【问题标题】:UIButton inside view controller not responding to any action视图控制器内的 UIButton 不响应任何操作
【发布时间】:2014-10-22 15:05:24
【问题描述】:

我正在创建一个带有按钮和选择器视图的视图控制器,如下所示,问题是按钮不响应任何操作,即 dismissButtonPushed 未调用

    UIViewController* x=[[UIViewController alloc]init];
    UIButton* btn=[[UIButton alloc]init];
    btn.frame = CGRectMake(50,80,250,50);
    [btn setTintColor:[UIColor blueColor]];
    [btn addTarget:self action:@selector(dismissButtonPushed:) forControlEvents:UIControlEventTouchUpInside];
    [btn setEnabled:true];
    [btn setTitle:@"Dismiss" forState:UIControlStateNormal];
    [x.view setBounds:CGRectMake(0,-250, 350,350)];
    [x.view addSubview:btn];
    [x.view addSubview:self.productfamilyPikerview];
    x.modalPresentationStyle=UIModalPresentationOverCurrentContext;
    [self.searchButton setHidden:true];
    [self presentViewController:x animated:YES completion:nil];

这里还有dismissButtonPushed 方法:

-(void)dismissButtonPushed:(id)sender{

}

【问题讨论】:

  • 按钮是否响应您的触摸?你用透明的东西盖住了吗?

标签: ios objective-c uiviewcontroller uibutton


【解决方案1】:

改变这一行

[btn addTarget:x action:@selector(dismissButtonPushed:) forControlEvents:UIControlEventTouchUpInside];

[btn addTarget:self action:@selector(dismissButtonPushed:) forControlEvents:UIControlEventTouchUpInside];

希望对你有帮助!

【讨论】:

  • 如果有帮助,请将其标记为接受的答案,以供将来搜索相同内容的用户使用。谢谢。
  • 如果这是(唯一的)问题,那么 OP 将会崩溃。
  • OP 代表什么?
  • 原始海报(提出问题的用户,性别中立)。 netforbeginners.about.com/od/internetlanguage/f/What-Is-OP.htm
猜你喜欢
  • 1970-01-01
  • 2015-08-01
  • 1970-01-01
  • 1970-01-01
  • 2016-11-13
  • 2012-02-19
  • 1970-01-01
  • 1970-01-01
  • 2016-11-02
相关资源
最近更新 更多