In viewDidLoad: - (void)viewDidLoad {super viewDidLoad];UIBarButtonItem not firing its action method
[self.navigationController setNavigationBarHidden:YES animated:NO];
UIToolbar *toolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
NSMutableArray *toolBarItems = [[NSMutableArray alloc] init];
[toolBarItems addObject:[[UIBarButtonItem alloc] initWithTitle:@"Articles" style:UIBarButtonItemStyleBordered target:self action:@selector(backButtonTapped)]];
[toolBarItems addObject:[[UIBarButtonItem alloc] initWithTitle:@"Source" style:UIBarButtonItemStyleBordered target:self action:nil]];
[toolBarItems addObject:[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil]];
[toolBarItems addObject:[[UIBarButtonItem alloc] initWithTitle:@"Aa" style:UIBarButtonItemStyleBordered target:self action:nil]];
[toolBarItems addObject:[[UIBarButtonItem alloc] initWithTitle:@"Rabbit" style:UIBarButtonItemStyleBordered target:self action:nil]];
[toolBar setBackgroundImage:[[UIImage alloc] init] forToolbarPosition:UIToolbarPositionAny barMetrics:UIBarMetricsDefault];
toolBar.items = toolBarItems;
[self.view addSubview:toolBar];
方法:
- (void)backButtonTapped {
[self.navigationController popViewControllerAnimated:YES];
}
我对里面的方法调用一个断点,但它永远不会被调用。为什么这个方法永远不会被调用?
你为什么要创建一个'UIToolbar'?为什么不使用导航控制器已经提供的工具栏?你在哪里调用'self.toolbarItems = toolBarItems'? – rmaddy 2013-04-27 18:37:52
因为我需要不同于导航栏提供的功能,而UIToolBars是推荐我去做的事情的推荐方式。该呼叫进一步下降。 – 2013-04-27 19:36:12
但是在什么时候,您将创建的'toolBar'添加到导航控制器或视图中?你有导航控制器吗? – 2013-04-27 19:46:21