我一直在开发我的图书应用程序,但我遇到了 UIBarButtonItem 困境。我已经在工具栏上设置了 3 个条形按钮,如下图所示。在我设置单击识别器(代码中的最后两行)之前,它们工作正常。我想要做的是通过单击而不是双击来退出此模式屏幕,而不是通过在工具栏上添加另一个“取消”按钮。在我设置单击识别器后,所有条形按钮项都不起作用。我怎样才能摆脱这个困境。谁能告诉我如何解决这个问题?感谢您的时间。
UIToolbar* toolbar = [[UIToolbar alloc] init];
toolbar.barStyle = UIBarStyleDefault;
[toolbar sizeToFit];
toolbar.frame = CGRectMake(0, 410, 320, 50);
toolbar.tintColor = _label.backgroundColor;
self.title = @"Test For Toolbar";
UIBarButtonItem* TofC = [[UIBarButtonItem alloc] initWithTitle:@"T of C"
style:UIBarButtonItemStyleBordered
target:self
action:@selector(showTofC)];
UIBarButtonItem* bookMark =
[[UIBarButtonItem alloc] initWithTitle:@"Book Mark"style:UIBarButtonItemStyleBordered
target:self
action:@selector(bookMarkIt)];
UIBarButtonItem* searchBtn = [[UIBarButtonItem alloc] initWithTitle:@"Search"
style:UIBarButtonItemStyleBordered
target:self
action:@selector(searchIt)];
UIBarButtonItem* spacer = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace
target:self
action:nil];
NSArray* buttons =
[NSArray arrayWithObjects:TofC, spacer, bookMark, spacer, searchBtn, nil];
self.navigationController.toolbarHidden = NO;
[toolbar setItems:buttons animated:NO];
[self.view addSubview:toolbar];
/*
// Single Tap
UITapGestureRecognizer* tapGesture = [[UITapGestureRecognizer alloc]
initWithTarget:self
action:@selector(handleTapGesture:)];
[self.view addGestureRecognizer:tapGesture];
*/
// Single Tap
Dum2ViewController* dum2ViewController = [[Dum2ViewController alloc] init];
UITapGestureRecognizer* tapGesture = [[UITapGestureRecognizer alloc]
initWithTarget:dum2ViewController
action:@selector(handleTapGesture:)];
[dum2ViewController.view addGestureRecognizer:tapGesture];