如何更改 UINavigationControler 上的后退按钮
在视图中,我想更改它,因为我有以下代码,但它失败了。
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
//Logout button
UIBarButtonItem * logout = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(goBack)];
logout.title = @"Logout";
nav_delegate.navigationController.navigationItem.leftBarButtonItem = logout;
[logout release];
}
感谢您的帮助。
In the view I want to change it for I have the following code but it fails.
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
//Logout button
UIBarButtonItem * logout = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(goBack)];
logout.title = @"Logout";
nav_delegate.navigationController.navigationItem.leftBarButtonItem = logout;
[logout release];
}
Thank you for any help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
实现 backBarButtonItem 是针对使用pushViewController:subViewController 的超级视图控制器。
例如,如果您为其超级视图控制器 Logout 推送了一个视图控制器:
那么,您应该在超级视图(即 Logout 视图)中实现 backBarButtonItem,不在推送的子ViewController 中。
因此,要实现 backBarButtonItem,您可以在超级视图 Logout 中执行此操作,例如:
您可以在 -(void)viewDidLoad 中执行此操作以进行静态使用,或在 -(void)viewWillAppear:(BOOL)animated 中执行此操作以进行动态使用,用于设置标题无需分配和初始化。
还有一点提示:在界面生成器中,有一个 backBarButtonItem 标题的输入字段。但如果你没有输入,你必须在.m文件中分配并初始化带有title的backBarButton,如上面的代码。如果您输入了静态使用的标题,我相信您可以简单地通过使用来更改它:
希望它有帮助。
Implementing backBarButtonItem is for the super view controller which uses pushViewController:subViewController.
For example, if you've pushed a view controller for its super view controller Logout:
Then, you should've implemented backBarButtonItem in the super view, which is Logout view, NOT in the pushed subViewController.
So, to implement backBarButtonItem, you do it in super view Logout, like:
You can do this in -(void)viewDidLoad for static use, or in -(void)viewWillAppear:(BOOL)animated for dynamic use, for setting the title without allocating and initializing.
One more tip: In interface builder, there is input field for backBarButtonItem title. But if you didn't enter, you must allocate and initialize the backBarButton with title in .m files, like the code above. If you've entered the title for static use, I believe you can change it simply by using:
Hope it helped.
在前一个视图控制器(按下后退按钮时将返回到的视图控制器)上设置
backBarButtonItem
。Set the
backBarButtonItem
on the previous view controller (the one that you will return to when you press the back button).答案如下。在视图控制器中:
Here's the answer. In the view controller: