我的 Storyboard是这样的:
所以从导航 Controller ,我要去一个选项卡 Controller 。 我的选项卡 Controller 有其分类,名为:MYTabBarView
在 MyTabBarView.m 的 ViewDidLoad 方法中,我以编程方式创建了右栏按钮项,如下所示:
UIBarButtonItem *homeButton = [[UIBarButtonItem alloc] initWithTitle:@"Home" style:UIBarButtonSystemItemAction target:self action:@selector(homeButtonAction)];
self.navigationItem.rightBarButtonItem=homeButton;
我的问题是如何为它编写一个 Action 。我的意思是,如果它是 Storyboard中可见的按钮,我会将其“拖放到”.h 文件和 .m 文件中
方法:
现在我该怎么办?
- (IBAction)home:(id)sender {
....
}
最佳答案
使用您在创建按钮时键入的选择器:
- (void)homeButtonAction {
// Code
}
如果您想传递发件人,请使用 @selector(homeButtonAction:)
和以下方法:
- (void)homeButtonAction:(id)sender {
// Code
}
关于ios - 从以编程方式创建的导航栏项设置操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12343203/