【问题标题】:Button Not working iOS按钮不工作 iOS
【发布时间】:2012-08-18 19:14:04
【问题描述】:

我在 IB 中插入了一个按钮,在 .h 文件中添加了这段代码

-(IBAction)buttonPressed:(id)sender;

将动作连接到 IB 中的按钮(Touch Up Inside),然后将其放在 @synthesize 正下方的 .m 文件中

-(IBAction)buttonPressed:(id)sender { 
       NSLog(@"Button pressed"); 
       ...
}

控制台中没有显示任何内容,因此由于某种原因未执行该操作。为什么是这样?谢谢。

【问题讨论】:

  • 如何创建包含buttonPressed: 代码的对象(视图控制器?)?
  • 好吧,视图控制器是预制的。
  • 您确定 viewController 被实例化为您期望的子类。例如[[MyViewController alloc] init]
  • @jsttn 你找到答案了吗?我也有类似的问题!

标签: iphone ios button


【解决方案1】:

我觉得这个方法很好。仔细检查:

  1. 您已在 IB 中将包含按钮的视图控制器的类设置为正确的类。

  2. 当您右键单击 IB 中的按钮时,它会连接 IBAction

【讨论】:

    【解决方案2】:

    您没有显示其余代码 - 它应该看起来像

    YourViewController *yourViewController = [[YourViewController alloc] initWithNibName:@"YourViewController" bundle:nil];
    yourViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
    [self presentModalViewController:yourViewController animated:YES];
    

    确保您已将 YourViewController.h 包含在调用 View Controller 的 .m 中。

    【讨论】:

    • 我想知道这是否可行。如果NSLog 没有打印任何内容,则很可能整个IBAction 没有被执行。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-04-27
    • 2016-01-05
    • 1970-01-01
    • 2017-07-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多