将目标添加到navigationBar中的库存后退按钮 [英] Add target to stock back button in navigationBar

查看:99
本文介绍了将目标添加到navigationBar中的库存后退按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 UINavigationBar 中设置标题和后退按钮的值,如下所示:

I am setting the values of the title and back button in the UINavigationBar as follows:

self.navigationItem.title = @"Post";
[self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName : [[UIColor blueColor] colorWithAlphaComponent:0.75f],
                                                                  NSFontAttributeName : [UIFont fontWithName:@"HelveticaNeue" size:20]}];
[self.navigationController.navigationBar.backItem setTitle:@"Pop Pop !"];

但是我无法将目标添加到后退按钮。我尝试了以下内容:

But i am unable to add target to the backbutton. I have tried the following:

[self.navigationItem.backBarButtonItem setTarget:self];
[self.navigationItem.backBarButtonItem setAction:@selector(goBack:)];

self.navigationItem.backBarButtonItem.target = self;
self.navigationItem.backBarButtonItem.action = @selector(goBack:);

但弹出viewController时我的选择器没有被调用。

But my selector is not being invoked on popping the viewController.

如何将目标添加到backButton,或者在弹出viewController时调用选择器?
(我已经尝试了SO中提到的所有可能的解决方案,徒劳无功)

How do I add a target to the backButton, or invoke a selector on popping the viewController ? (I have tried all possible solutions mentioned in SO, in vain)

编辑:我更愿意编辑股票backButton的行为,而不是将自定义按钮设置为backButton。

I would to prefer to edit the behaviour of the stock backButton, instead of setting a custom button as the backButton.

推荐答案

我有两个解决方案,让您无法添加目标或操作你的后退按钮:

I have two solutions for you, giving that you cannot add a target or action to your back button:

1-添加一个新的barButtonItem并调用它,然后将你的选择器添加到它,并将它放在navigationItem.leftBarButtonItem中。不要忘记弹出!

1- Add a new barButtonItem and call it whatever and add your selector to it, and put it in the navigationItem.leftBarButtonItem. Don't forget to pop!

2-覆盖viewWillDisAppear方法,并做你想做的任何事情..如果你的viewcontroller没有引导你到另一个viewcontroller但是前一个...

2- Override the viewWillDisAppear method, and do whatever you wanna do there.. if your viewcontroller doesn't direct you to another viewcontroller but the previous one...

如果您还有其他问题,请询问(Y)

if you have any more questions, just ask (Y)

这篇关于将目标添加到navigationBar中的库存后退按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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