简体   繁体   English

修改从UITabBarController的“更多”选项卡显示的选项卡的导航栏上的“更多”按钮

[英]Modify the More button on the Navigation bar of a tab displayed from a UITabBarController's More tab

I have an app with a UITabBarController that has more than five tabs. 我有一个带有UITabBarController的应用程序,该应用程序具有五个以上的选项卡。

在此处输入图片说明

When I press the More tab, I go to the moreNavigationController which is a UINavigationController . 当我按“ 更多”选项卡时,我转到moreNavigationController ,它是一个UINavigationController

在此处输入图片说明

As you can see, I have figured out how to style the Title , Tint , Table color , and the Edit button on the More screen, as well as the Configure screen from pressing the Edit button. 正如你所看到的,我已经找到了如何风格的标题色调表色 ,和更多屏幕上的编辑按钮,以及从按下Edit按钮配置屏幕。

What I have not been able to figure out is how to style the back button, titled More , when I select an item in the table. 当我在表格中选择一个项目时,我还无法弄清如何设置后退按钮的样式,该标题为“ 更多 ”。

在此处输入图片说明

Each tab has it's own class, GRWTabSettingsViewController for example, which inherits from GRWViewController , which provides common functionality for all tabs, which then inherits from UIViewController . 每个选项卡都有其自己的类,例如GRWTabSettingsViewController该类继承自GRWViewController ,后者为所有选项卡提供通用功能,然后继承自UIViewController

When on the Settings screen (or any other tab), I am trying to edit the More back button. 在“ 设置”屏幕(或任何其他标签)上时,我正在尝试编辑“ 更多后退”按钮。

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];

    [(UIBarButtonItem *)[(UINavigationItem *)[(UINavigationBar *)[(UINavigationController *)[self navigationController] navigationBar] topItem] leftBarButtonItem] setTintColor:[UIColor darkGrayColor]]; 
    [self.navigationController.navigationBar.topItem.leftBarButtonItem setTintColor:[UIColor darkGrayColor]];
}

However, this navigationController is clearly the parent since these changes get applied to the More screen and not the Settings screen. 但是,此NavigationController显然是父级,因为这些更改将应用​​于“ 更多”屏幕,而不是“ 设置”屏幕。

What am I misunderstanding and how would I modify the buttons displayed on the navigation bar of the screen I am viewing? 我有什么误解,如何修改正在查看的屏幕的导航栏上显示的按钮?

=== SOLUTION === ===解决方案===

在此处输入图片说明

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];

    // use backBarButtonItem not leftBarButtonItem
    //[(UIBarButtonItem *)[(UINavigationItem *)[(UINavigationBar *)[(UINavigationController *)[self navigationController] navigationBar] topItem] leftBarButtonItem] setTintColor:[UIColor darkGrayColor]];
    //[self.navigationController.navigationBar.topItem.leftBarButtonItem setTintColor:[UIColor darkGrayColor]];

    UIBarButtonItem *backButton = [[UIBarButtonItem alloc]
                                   initWithTitle:self.navigationController.navigationBar.topItem.title
                                   style:UIBarButtonItemStylePlain
                                   target:nil
                                   action:nil];
    [backButton setTintColor:[UIColor darkGrayColor]];

    self.navigationController.navigationBar.topItem.backBarButtonItem = backButton;
    // these do not work
    //[self.navigationController.navigationBar.topItem.backBarButtonItem setTintColor:[UIColor darkGrayColor]];
    //[backButton setTintColor:[UIColor darkGrayColor]];
}

Did take me a while to figure out that I can not format the button through self , or format the button after the assignment to self . 确实花了我一段时间才能弄清楚我无法通过self格式化按钮,也无法在分配给self之后格式化按钮。

你应该定制backBarButtonItem以前的导航项目的,不是的topItem

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM