1

viewDidLoad: - (void)viewDidLoad { [super viewDidLoad];

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

メソッド内の呼び出しにブレークポイントがありますが、呼び出されません。このメソッドが呼び出されないのはなぜですか?

4

3 に答える 3

5

UIBarButtonのタップをインターセプトするビュー全体にUITapGestureRecognizerがありました。UIToolBar の外にない限り、基本的に UITapGestureRecognizer の開始を停止したこの回答のおかげで解決しました。

于 2013-04-28T15:19:21.187 に答える
1

あなたのコードは完全ではなく、あなたがそれを実装していないのか、ここに書いていないのかわかりません。念のため、これはうまくいくはずです:

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)]];
toolBar.items = toolBarItems;
[self.view addSubview:toolBar];
于 2013-04-27T23:15:51.937 に答える
0

このようにしてみてください。その正常に動作します。

 UIToolbar *toolbar = [[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, 320, 44)];
    UIBarButtonItem *infoButton = [[UIBarButtonItem alloc]initWithTitle:@"back"style:UIBarButtonItemStyleBordered target:self action:@selector(backButtonTapped)];
    [toolbar setItems:[NSArray arrayWithObjects:infoButton,nil]];
    [self.view addSubview:toolbar];
于 2013-04-28T06:19:36.110 に答える