这是代码
UIBarButtonItem *button = [[UIBarButtonItem alloc] initWithTitle:@"Interpretations" style:UIBarButtonItemStyleBordered target:self action:@selector(showInterpretations:)];
self.navigationItem.rightBarButtonItem = button;
在我的程序中,当我创建一个按钮并设置它的标题时,默认值titleLabel.userInteractionEnabled
为YES
,这会导致同样的问题,所以我必须将UserInteractionEnabled
设置为{ {1}}以便按钮可以正确响应。
但是在导航栏中,NO
的类不是UIBarButtonItem
,我尝试使用UIView
创建UIBarButtonItem
并且效果很好,我认为在使用时initWithImage
1}}必须有一个initWithTitle
为YES的titleLabel。我仍然想知道它是如何发生的以及如何解决它,谢谢。
答案 0 :(得分:0)
我使用它并且它有效:D..hope它帮助了你:)
UIButton* backToRecent = [UIButton buttonWithType:UIButtonTypeCustom];
[backToRecent setImage:[UIImage imageNamed:@"navB_V.png"]forState:UIControlStateNormal];
[backToRecent setTitle:@"button title" forState:UIControlStateNormal];
[backToRecent addTarget:self action:@selector(deselect) forControlEvents:UIControlEventTouchUpInside];
[backToRecent setFrame:CGRectMake(0, 0, 45, 30)];
[backToRecent setImageEdgeInsets:UIEdgeInsetsMake(0, -30, 0, -30)];
UIBarButtonItem* navItem = [[UIBarButtonItem alloc]initWithCustomView:backToRecent];
[self.navigationItem setLeftBarButtonItem:navItem];