我在 IB 中插入了一个按钮,将此代码添加到 .h 文件中
-(IBAction)buttonPressed:(id)sender;
将动作连接到IB(内部触摸)中的按钮,然后将其放在正下方的.m文件中@synthesize
-(IBAction)buttonPressed:(id)sender {
NSLog(@"Button pressed");
...
}
控制台中未显示任何内容,因此由于某种原因未执行操作。这是为什么呢?谢谢。
这种方法对我来说似乎很好。仔细检查:
-
您已在 IB 中将包含按钮的视图控制器的类设置为正确的类。
-
当您右键单击 IB 中的按钮时,它已连接
IBAction
。
您没有显示其余代码 - 它应该看起来像
YourViewController *yourViewController = [[YourViewController alloc] initWithNibName:@"YourViewController" bundle:nil];
yourViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:yourViewController animated:YES];
确保您已在调用视图控制器的 .m 中包含 YourViewController.h。