我正在尝试实现一个类似日历的界面,带有左右箭头,允许用户及时向后滚动/向前滚动。为此,我使用了一个导航 Controller ,并在堆栈上推送/弹出 View 。
但是,如果我当前正在查看 Root View ,并且我无法弹出 View 以获得正确的动画方向,如果我试图及时导航回来怎么办?
我上周在 Stack Overflow 上发现了一篇文章,其中演示了一种方法,其中新 View 将被推送到当前 Root View 下方的堆栈中,从而允许 Root View 被弹出。这只是几行代码——主要是获取堆栈中当前项目的数组,并以某种方式将新 View 推到当前事件 View 下方。不幸的是,我似乎再也找不到那个特定的帖子了……
有没有人遇到过同一个链接,或者可以指出正确的方向?我早些时候让这个工作正常,但由于计算机故障,我的一些工作丢失了。
编辑:
通过一些实验,我已经部分工作了...
// create new view controller
ViewController *viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
// add below root
NSMutableArray *allViews = [[NSMutableArray alloc] initWithArray:self.navigationController.viewControllers];
[allViews insertObject:viewController atIndex:0];
[viewController release];
self.navigationController.viewControllers = allViews;
[[self navigationController] popViewControllerAnimated:YES];
[allViews release];
它似乎确实在泄漏内存,但是 - 如果我对 allViews 数组执行 NSLog,每次我及时前进然后返回到前一个 View 时,它似乎会向数组添加一个额外的 View ,但不会稍后再脱掉。这暂时可行,但希望我能解决这个问题。
最佳答案
UINavigationController Class Reference
我认为你在谈论 @property(nonatomic, copy) NSArray *viewControllers
引用引用:
Discussion
The root view controller is at index 0 in the array, the back view controller is at index n-2, and the top controller is at index n-1, where n is the number of items in the array.
Assigning a new array of view controllers to this property is equivalent to calling the setViewControllers:animated: method with the animated parameter set to NO.
这是您要查找的信息吗?
对于您正在尝试做的事情,您可以考虑 UIView 中的内容相反。
transitionFromView:toView:duration:options:completion:
Creates a transition animation between the specified views using the given parameters.
关于ios - 将 View 插入当前 Root View 下方的堆栈,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8490506/