模态视图控制器-UIBarButtonItems不持久 [英] Modal View Controllers - UIBarButtonItems Do Not Persist

查看:43
本文介绍了模态视图控制器-UIBarButtonItems不持久的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我介绍了模态视图控制器,包装在UINavigationController中。

I present modal view controllers, packaged in a UINavigationController.

当它们第一次出现时,条形按钮项就可以了。

When they first appear, the bar button items are alright.

但是,如果我单击一个按钮并将新的视图控制器推到UINavigationController,然后使用该视图控制器的后退按钮,它会弹出回到原始模式视图控制器按钮不会显示,(但当我单击它们时它们会起作用->只是看不到它们)

However, if I click a button and a new view controller is pushed to the UINavigationController, and then I use the back button of that view controller, and it gets popped back to the original modal view controller, the buttons do not show up, (but they work when I click them -> just can't see them)

我似乎无法弄清楚为什么会发生这种情况。

I can't seem to figure out why this occurs.

下面是一些代码。

哦,顺便说一下,我自定义了导航控制器的导航栏的背景。我感觉这可能是造成视觉干扰的原因,但是我不知道该怎么做才能使其正确。

Oh, and by the way, I customize the navigation controller's navigation bar's background. I have a feeling this may be causing this visual interference, but I don't know what to change to get it right.

在GGMainViewController中:

In 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中

In 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方法中设置的,为什么当我从另一个视图控制器返回到它们时,是否看不到它们(但它们仍然起作用)?

推荐答案

问题是:


  • 导航栏的渐变(按代码完成)

解决方案是:


  • 使用Sketch绘制渐变图像,然后使用外观代理将图像设置为背景图像

  • use Sketch to create an image of the gradients and use the appearance proxy to set the image as a background image

[[UINavigationBar外观] setBackgroundImage:[UIImage imageNamed:@ NavigationBarBackground] forBarMetrics :UIBarMetricsDefault];

这篇关于模态视图控制器-UIBarButtonItems不持久的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆