gpt4 book ai didi

ios - UIBarButtonItem 未触发其操作方法

转载 作者:行者123 更新时间:2023-12-01 17:41:58 24 4
gpt4 key购买 nike

在 viewDidLoad 中:
- (void)viewDidLoad
{
[ super View DidLoad];

[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];
}

我在方法内部的调用上有一个断点,但它永远不会被调用。为什么这个方法永远不会被调用?

最佳答案

我在整个 View 上有一个 UITapGestureRecognizer,它拦截了 UIBarButton 上的点击。感谢this answer,我解决了它,这基本上从一开始就停止了 UITapGestureRecognizer,除非它在 ​​UIToolBar 之外。

关于ios - UIBarButtonItem 未触发其操作方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16255540/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com