你好我已经检查过一些帖子,但找不到有关我问题的任何有用信息。我已经成功添加了一个按钮,但有时候按钮会出现在顶部。
我的代码:
self.navigationItem.leftBarButtonItem = nil;
self.navigationItem.backBarButtonItem = nil;
[self.navigationItem setHidesBackButton:YES];
UIButton *btn = [UIButton backButton];
[btn addTarget:self action:@selector(popView) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *barBtn = [[UIBarButtonItem alloc] initWithCustomView:btn];
self.navigationItem.leftBarButtonItem = barBtn;
[barBtn release];
结果:
所以也许有人有类似的问题或知道我做错了什么?
提前致谢!
答案 0 :(得分:1)
你需要更改一些代码......我在这里放了一些代码。
UIButton *leftButton = [UIButton buttonWithType:UIButtonTypeCustom];
[leftButton setUserInteractionEnabled:NO];
[leftButton setImage:[UIImage imageNamed:@"leftbutton.png"] forState:UIControlStateNormal];
leftButton.frame = CGRectMake(0, 0, 30, 30);
[leftButton addTarget:self action:@selector(youraction:) forControlEvents:UIControlEventTouchUpInside];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:leftButton];
[leftButton release];
希望,这可能对你有帮助..
答案 1 :(得分:1)
self.navigationItem.hidesBackButton = YES;
应该解决你的问题
答案 2 :(得分:1)
嗨lukas你可以使用下面的代码,因为它对我来说很好....
UINavigationBar * bar; UIImage * buttonImage = [UIImage imageNamed:@“bak.png”]; UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setImage:buttonImage forState:UIControlStateNormal];
[button addTarget:self action:@selector(popView) forControlEvents:UIControlEventTouchUpInside];
button.frame = CGRectMake(0, 0, buttonImage.size.width, buttonImage.size.height);
customBarItem = [[UIBarButtonItem alloc] initWithCustomView:button];
self.navigationItem.leftBarButtonItem=customBarItem;
[bar addSubview:button];
如果您需要澄清,请告诉我....
答案 3 :(得分:0)
最后我发现了它是什么。导航控制器和呈现视图控制器存在一些问题,因此在修复它们之后,这个错误就消失了。