gpt4 book ai didi

iphone - iOS 中从右到左的 NavigationController

转载 作者:可可西里 更新时间:2023-11-01 05:41:58 25 4
gpt4 key购买 nike

我正在构建一个从右到左的导航 Controller 来支持 RTL 语言。阅读 StackOverFlow 中的一些帖子后 Push ViewController from Right To Left with UINavigationController ,我认为这种方法最合适:

DetailedViewController *DVC = [[DetailedViewController alloc]initWithNibName:@"DetailedViewController" bundle:nil];
NSMutableArray *vcs = [NSMutableArray arrayWithArray:self.navigationController.viewControllers];
[vcs insertObject:DVC atIndex:[vcs count]-1];
[self.navigationController setViewControllers:vcs animated:NO];
[self.navigationController popViewControllerAnimated:YES];

这将创建一个详细的 View Controller 并将其添加到 NavigationController 正下方的 View Controller 堆栈中。当弹出 NavigationController 时,看起来就像我们实际上正在加载 DetailedViewController,整洁,是吗?

现在我面临两个问题:

1- 详细 View Controller 不再显示返回按钮。所以我决定添加一个新按钮来代表它执行此操作。

2- 我不知道如何从 DetailedViewController 返回到 NavigationController。

有什么想法吗?

最佳答案

考虑到您实际上是在侵入导航 Controller ,为了保持行为的一致性,您需要对其进行更多侵入。

弹出导航 Controller 会将其从内存中释放出来,因此您可能需要另一个包含弹出 Controller 的数组或堆栈(从用户的角度来看是推送 Controller ,因为据我所知,您会在需要推送时弹出,并在需要弹出时推送)。在该阵列/堆栈中,您将保留需要返回的 Controller ,在弹出它们之前将它们插入阵列/堆栈。

我假设可变数组存在于某个地方,您可以随时访问它,为了简单起见,将其称为 otherNavigationController:

DetailedViewController *DVC = [[DetailedViewController alloc]initWithNibName:@"DetailedViewController" bundle:nil];
NSMutableArray *vcs = [NSMutableArray arrayWithArray:self.navigationController.viewControllers];
[vcs insertObject:DVC atIndex:[vcs count]-1];
[self.navigationController setViewControllers:vcs animated:NO];
[otherNavigationController addObject:self];
[self.navigationController popViewControllerAnimated:YES];

至于问题的第二部分,您需要添加自定义后退按钮,因为默认的后退按钮不适合您。自定义按钮应该在按下时从上述数组/堆栈的顶部推送一个 View Controller (从用户的角度弹出它)。

pop 函数的代码应该是这样的:

UIViewController *previousViewController = [otherNavigationController lastObject];
[otherNavigationController removeLastObject];
[self.navigationController pushViewController:previousViewController animated:YES];

免责声明:此处的代码未经试用和测试,我什至不确定这是否可行,但它应该能让您上手。祝你好运!

关于iphone - iOS 中从右到左的 NavigationController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12021689/

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