导航栏按钮未显示 [英] Navigation bar button not showing
本文介绍了导航栏按钮未显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当尝试在左侧和右侧添加导航按钮时,该按钮未显示?这是我使用的代码吗?这是怎么回事?
When try to add a navigation button on left and right side , its not showing?is this is the code i used for, Whats wrong with this?
这是我在appdelegate中添加导航栏的方式,
this is how i added the navigation bar in in appdelegate,
UIViewController *viewController1 = [[logyFirstViewController alloc] initWithNibName:@"logyFirstViewController" bundle:nil];
UIViewController *viewController2 = [[logySecondViewController alloc] initWithNibName:@"logySecondViewController" bundle:nil];
UIViewController *viewController3 = [[record alloc] initWithNibName:@"record" bundle:nil];
UIViewController *viewController4 = [[searchview alloc] initWithNibName:@"searchview" bundle:nil];
UIViewController *viewController5 = [[profilde alloc] initWithNibName:@"profilde" bundle:nil];
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = @[viewController1, viewController2, viewController3, viewController4, viewController5];
navigationController = [[UINavigationController alloc] initWithRootViewController:self.tabBarController];
self.navigationController.navigationBar.barStyle=UIBarStyleDefault;
[navigationController.navigationBar setAlpha:0.8f];
[self.window addSubview:[navigationController view]];
button4 = [UIButton buttonWithType:UIButtonTypeCustom];
[button4 setFrame:CGRectMake(0.0f, 0.0f, 25.0f, 25.0f)];
[button4 addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
[button4 setImage:[UIImage imageNamed:@"del.png"] forState:UIControlStateNormal];
UIBarButtonItem *random1 = [[UIBarButtonItem alloc] initWithCustomView:button4];
self.navigationController.navigationItem.leftBarButtonItem=random1;
请帮助.
推荐答案
我认为您的代码没有错只需检查您的图像或尝试使用圆角的rect图像进行测试
I see nothing wrong with your code just check your image or try with a rounded rect image to test
UIButton* button4 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button4 setFrame:CGRectMake(0.0f, 0.0f, 25.0f, 25.0f)];
[button4 addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *random1 = [[UIBarButtonItem alloc] initWithCustomView:button4];
并使用 self.navigationController.navigationBar.topItem.leftBarButtonItem = random1;
代替 self.navigationController.navigationItem.leftBarButtonItem = random1;
这篇关于导航栏按钮未显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文