viewcontroller怎么样实现页面的任意跳转呀?例如A->B->C之后怎么样直接C->A呢

iOS 码拜 8年前 (2016-03-23) 896次浏览
如题,网上看的方法
pushview 和 popview之类的   都是压栈式的切换    例如a->b->c  那么只能 c->b->a    怎么样直接c->a呢,   假如在c里面直接pushview:a  是不是就会实例化2个a了呢,这样感觉也不符合跳转的规则呢
解决方案

10

直接setViewControllers就行了。
相似于这样:[self.navigationController setViewControllers:viewControllers animated:YES];
这是一种标准做法,就像iOS系统快速进入某个设置页面一样。

5

引用:
Quote: 引用:

直接setViewControllers就行了。
相似于这样:[self.navigationController setViewControllers:viewControllers animated:YES];
这是一种标准做法,就像iOS系统快速进入某个设置页面一样。

这样多次调用同一个页面     setViewControllers会不会实例化很多个这个页面的对象呢?

假如viewControllers里面本身就有你要的vc,你就把viewControllers复制一份,删掉其他不要的vc就可以了

5

用这个方法:    [self.navigationController popToViewController:vc animated:YES];
下面英文是这个方法的注释。
大致意思:弹出ViewController 直到指定的VC在栈顶。参数是你要跳的那个VC。要用这个方法,就需要你在跳的时候,持有要调到的VC的实例。
当然,你要一下子调到第一个更简单:    [self.navigationController popToRootViewControllerAnimated:YES];
这个方法就搞定,不需要其他任何参数。

– (NSArray *)popToViewController:(UIViewController *)viewController animated:(BOOL)animated
Description
Pops view controllers until the specified view controller is at the top of the navigation stack.
For information on how the navigation bar is updated, see Updating the Navigation Bar.
Parameters
viewController
The view controller that you want to be at the top of the stack. This view controller must currently be on the navigation stack.
animated
Set this value to YES to animate the transition. Pass NO if you are setting up a navigation controller before its view is displayed.
Returns
An array containing the view controllers that were popped from the stack.
Availability iOS (2.0 and later)
Declared In UINavigationController.h
Reference UINavigationController Class Reference

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明viewcontroller怎么样实现页面的任意跳转呀?例如A->B->C之后怎么样直接C->A呢
喜欢 (0)
[1034331897@qq.com]
分享 (0)