1

我的故事板是这样的:

故事板

所以从导航控制器,我要去一个标签控制器。我的标签控制器有它的分类,命名为:MYTabBarView

在 MyTabBarView.m 中,在其 ViewDidLoad 方法中,我以编程方式创建了右栏按钮项,如下所示:

 UIBarButtonItem *homeButton = [[UIBarButtonItem alloc] initWithTitle:@"Home" style:UIBarButtonSystemItemAction target:self action:@selector(homeButtonAction)];

self.navigationItem.rightBarButtonItem=homeButton;

我的问题是如何为它写一个动作。我的意思是,如果它是故事板中可见的按钮,我会将其“拖放”到 .h 文件和 .m 文件中

方法:

现在我该怎么办?

- (IBAction)home:(id)sender {
....
}
4

1 回答 1

2

使用您在创建按钮时键入的选择器:

- (void)homeButtonAction {
    // Code
}

如果你想传递发件人使用@selector(homeButtonAction:)和以下方法:

- (void)homeButtonAction:(id)sender {
    // Code
}
于 2012-09-09T21:43:46.817 回答