gpt4 book ai didi

ios - 在 ios6/ios 7 兼容应用程序中更改 Navigatiobar 后退按钮操作

转载 作者:行者123 更新时间:2023-11-28 22:17:31 25 4
gpt4 key购买 nike

我有一个导航 Controller 应用程序,我需要为导航后退栏按钮设置自定义操作。尝试了一些解决方法,但尚未找到解决方案。

尝试过

  UIBarButtonItem *backBarItem  = self.navigationItem.leftBarButtonItem;
backBarItem.target = self;
backBarItem.action = @selector(popToHomeViewController);

结果:无效。后退按钮弹出到导航堆栈中的前一个 viewController

  UIBarButtonItem *customBarItem = [[UIBarButtonItem alloc] initWithTitle:backBarItem.title style:backBarItem.style target:self action:@selector(popViewController)];
self.navigationItem.leftBarButtonItem = customBarItem;

结果:无效。后退按钮弹出到导航堆栈中的前一个 viewController

  UIBarButtonItem *customBarItem = [[UIBarButtonItem alloc] initWithTitle:@"back" style:backBarItem.style target:self action:@selector(popViewController)];
self.navigationItem.leftBarButtonItem = customBarItem;

结果:现在我的选择器被完美调用并导航到所需的 viewController。这里的问题是后退按钮不像 native 后退按钮。它没有粗体“<”字符,因为我没有提到它。如果添加 < 字符,则需要更改它以实现 ios 6 兼容性。

是否有更好的解决方案来确保带有自定义选择器的 ios 6 和 ios 7 兼容导航后退按钮?

最佳答案

试试这个简单的例子会帮助你..

- (void)viewDidLoad {
[super viewDidLoad];
UIImage *buttonImage = [UIImage imageNamed:@"back.png"];

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];

[button setImage:buttonImage forState:UIControlStateNormal];


button.frame = CGRectMake(0, 0, buttonImage.size.width, buttonImage.size.height);

[button addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];

UIBarButtonItem *customBarItem = [[UIBarButtonItem alloc] initWithCustomView:button];

self.navigationItem.leftBarButtonItem = customBarItem;
[customBarItem release];
}

-(void)back {

[self.navigationController popViewControllerAnimated:YES];
}

确保您的资源文件夹中有一个按钮图像,其大小与导航栏后退按钮的大小相同,名称为 back.png

如果需要任何其他帮助,请随时联系。

快乐编码!!!!!

关于ios - 在 ios6/ios 7 兼容应用程序中更改 Navigatiobar 后退按钮操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21276678/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com