如何从其他.h文件导入IBActions?

tom*_*Dev 2 iphone xcode ipad

我的iOS应用程序上有很多视图控制器,其中大多数都需要完全相同的IBAction.

因此,不是在所有视图控制器中编写相同的代码,是否可以使用IBActions创建一个单独的.h文件,然后在viewcontroller.h上导入?

我尝试创建一个Actions.h文件并使用ViewController.h文件中的命令"#import Actions.h"导入它,但是当我转到Interface Builder时,操作不会显示.有没有办法做到这一点?

Dav*_*eyl 5

在超类中定义方法:

@interface MyActionViewController: UIViewController
{
}

- (IBAction)theAction:(id)sender;

@end
Run Code Online (Sandbox Code Playgroud)

从中对视图控制器进行子类化:

@interface FirstViewController: MyActionViewController
{
}

@end
Run Code Online (Sandbox Code Playgroud)