我展示了封装在 UINavigationController 中的模态视图控制器。
当它们第一次出现时,条形按钮项是好的。
但是,如果我单击一个按钮并将一个新的视图控制器推送到 UINavigationController,然后我使用该视图控制器的后退按钮,它会弹出回原始模式视图控制器,则按钮不会显示,(但是当我单击它们时它们会起作用->只是看不到它们)
我似乎无法弄清楚为什么会发生这种情况。
这是一些代码。
哦,顺便说一下,我自定义了导航控制器的导航栏背景。我有一种感觉,这可能会导致这种视觉干扰,但我不知道要改变什么才能让它正确。
在 GGMainViewController 中:
GGSelectTeamsViewController *chooseTeam = [[GIFSelectTeamsViewController alloc] init];
UINavigationController* navigationController = [[UINavigationController alloc] initWithRootViewController:chooseTeam];
[self setupModalNavigationBar:navigationController];
[self presentViewController:navigationController animated:YES completion:nil];
- (void)setupModalNavigationBar:(UINavigationController *)nav {
// unnecessary code removed for a quicker read
// basically navigation bar has a background gradient as well as a bottom border
[nav.navigationBar.layer addSublayer:bottomBorder];
[nav.navigationBar.layer addSublayer:gradient];
}
在 GGSelectTeamsViewController
- (void)viewDidLoad
{
[super viewDidLoad];
title = [[UILabel alloc] init];
title.text = someText;
title.backgroundColor = [UIColor clearColor];
title.textColor = [UIColor whiteColor];
self.navigationItem.titleView = title;
[title sizeToFit];
UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];
[backButton setTitle:@"Back" forState:UIControlStateNormal];
[backButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
backButton.frame = someFrame;
[backButton addTarget:self action:@selector(goBack) forControlEvents:UIControlEventTouchUpInside];
[self.navigationItem setLeftBarButtonItem:[[UIBarButtonItem alloc] initWithCustomView:backButton] animated:NO];
UIButton *selectButton = [UIButton buttonWithType:UIButtonTypeCustom];
[selectButton setTitle:@"Select" forState:UIControlStateNormal];
[selectButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
selectButton.frame = someFrame;
[selectButton addTarget:self action:@selector(sendContent) forControlEvents:UIControlEventTouchUpInside];
[self.navigationItem setRightBarButtonItem:[[UIBarButtonItem alloc] initWithCustomView:selectButton] animated:NO];
}
既然导航项是在 viewDidLoad 方法中设置的,为什么当我从另一个视图控制器返回它时,我看不到它们(但它们仍然有效)?