iOS中从右到左的NavigationController

ala*_*usi 4 iphone uitableview uiviewcontroller ios

我正在构建一个从右到左的导航控制器来支持 RTL 语言。在阅读 StackOverFlow 中的一些帖子后,使用 UINavigationController 从右到左推送 ViewController,我认为这种方法最合适:

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];
Run Code Online (Sandbox Code Playgroud)

这将创建一个详细的视图控制器并将其添加到 NavigationController 正下方的视图控制器堆栈中。当弹出 NavigationController 时,它看起来好像我们真的在加载DetailedViewController,整洁,嗯?

现在我面临两个问题:

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

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

有任何想法吗?

Adi*_*dis 5

考虑到您本质上是在入侵导航控制器,为了保持行为的一致性,您需要对其进行更多的入侵。

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

我假设可变数组存在于您可以随时访问的地方,并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];
Run Code Online (Sandbox Code Playgroud)

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

pop 函数的代码如下所示:

UIViewController *previousViewController = [otherNavigationController lastObject];
[otherNavigationController removeLastObject];
[self.navigationController pushViewController:previousViewController animated:YES];
Run Code Online (Sandbox Code Playgroud)

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