1

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

-(IBAction)buttonPressed:(id)sender;

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

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

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

4

2 回答 2

1

该方法对我来说似乎很好。仔细检查:

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

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

于 2012-08-18T19:20:40.253 回答
0

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

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

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

于 2012-08-18T21:03:08.960 回答