简体   繁体   English

导航栏中的更新后退按钮

[英]Update back button in navigationbar

if i change the title of the parentViewController, how do i update the back button displayed in the upper left corner of the child view. 如果我更改parentViewController的标题,如何更新子视图左上角显示的后退按钮。 ?

i already know to set self.title when i am actually displaying the parent view, but i would like to know how to refresh the button with the new title displayed in the child view while i am looking at the child view. 当我实际显示父视图时,我已经知道要设置self.title,但是我想知道如何在查看子视图时用子视图中显示的新标题刷新按钮。 i have tried 我努力了

self.parentViewController.title = @"foo"

and

self.parentViewController.navigationItem.title = @"foo"

尝试这个:

self.parentViewController.navigationItem.backBarButtonItem.title = @"foo";

You need to set the title for the navigationItem that belongs to the 'previous' controller. 您需要为属于“上一个”控制器的navigationItem设置标题。 So in a navigationController that would be the one 'to the left'. 因此,在navigationController中,那将是“左侧”。

You can set this title first and then push the new view onto the stack. 您可以先设置此标题,然后将新视图推入堆栈。

What I ended up doing was implementing a delegate protocol. 我最终要做的是实现委托协议。 my child view tells the parent the new name and the parent sets its title. 我的孩子视图告诉父母新名称,然后父母设置标题。 with self.title = @"foo" 与self.title = @“ foo”

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

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