“标题”的问题在 UINavigationController 中

发布于 2024-11-11 17:33:24 字数 497 浏览 7 评论 0原文

我的标题和 UINavigationController 遇到问题。我在 UIViewControllerCurrent 使用以下代码,当我从 NextViewController 返回时,导航栏的标题仍然是“上一个”..任何人都可以帮我解决这个问题吗?谢谢。

[self setTitle:@"Previous"]; 
NextViewController *controller = [[NextViewController alloc] init]; 
[[self navigationController] pushViewController:controller animated:YES]; 
[controller release], controller = nil; 

- (void)viewWillAppear:(BOOL)animated; {     
[self setTitle:@"Real Title"];     
[super viewWillAppear:animated]; } 

I am having a problem with title and UINavigationController. I am using the following code at UIViewControllerCurrent and when I get back from NextViewController, the title of the NavBar is still "Previous" ..Can anyone kindly help me out with this problem ? Thanks.

[self setTitle:@"Previous"]; 
NextViewController *controller = [[NextViewController alloc] init]; 
[[self navigationController] pushViewController:controller animated:YES]; 
[controller release], controller = nil; 

- (void)viewWillAppear:(BOOL)animated; {     
[self setTitle:@"Real Title"];     
[super viewWillAppear:animated]; } 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

哥,最终变帅啦 2024-11-18 17:33:24

我会尝试交换这两行,

[self setTitle:@"Real Title"];     
[super viewWillAppear:animated];

以便您得到

[super viewDidAppear:animated];
[self setTitle:@"Real Title"];

,我会将它们放入 viewDidAppear 中。

I would try to exchange the two lines

[self setTitle:@"Real Title"];     
[super viewWillAppear:animated];

so that you get

[super viewDidAppear:animated];
[self setTitle:@"Real Title"];

and I would put these into viewDidAppear.

涫野音 2024-11-18 17:33:24

尝试使用下面的 UINavigationController 委托方法。

- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated;
- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated;

使用委托方法之一来更改标题。

Try using UINavigationController delegate methods below.

- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated;
- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated;

Use one of the delegate method to change title.

仅冇旳回忆 2024-11-18 17:33:24

如果 dasdoms 解决方案不起作用,请尝试以下操作。

在弹出之前的 NextViewController 中运行此代码。

for (int i =0; i < [[self.navigationController viewControllers] count]; i++)
    {
        UIViewController *aController = [[self.navigationController viewControllers] objectAtIndex:i];

        if ([aController isKindOfClass:[PreviousViewController class]])
        {
            PreviousViewController *aPreviousViewController = (PreviousViewController *)aController;
            aPreviousViewController.title = @" Real Title";
        }

    }

If dasdoms solution is not working the try the following.

In the NextViewController just before poping out run this code.

for (int i =0; i < [[self.navigationController viewControllers] count]; i++)
    {
        UIViewController *aController = [[self.navigationController viewControllers] objectAtIndex:i];

        if ([aController isKindOfClass:[PreviousViewController class]])
        {
            PreviousViewController *aPreviousViewController = (PreviousViewController *)aController;
            aPreviousViewController.title = @" Real Title";
        }

    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文