navigation切换相关


navigation切换相关

通过官方文档可以知道:navigation controller本身就是一个管理view controller层级的对象,但它最灵活的地方在于,可以跨界面跳转和很简单的实现自定义动画(参照http://iostrack.com/post/2012-08-17/40036208779)。

我们来看下navigation对栈的管理方法

– pushViewController:animated://推送显示新的viewController

– popViewControllerAnimated://返回到上一级的viewController

– popToRootViewControllerAnimated://返回到rootViewController

– popToViewController:animated://跳转到指定的viewController,实际上相当于返回到栈序列中的第几项,处于该项上面的实例将会被释放(收到dealloc事件)

各具一个实例吧:

– pushViewController:animated:

xib下:

DemoViewController *demoViewController = [[DemoViewController alloc] initWithNibName:@"DemoViewController" bundle:[NSBundle mainBundle]];

[self.navigationController pushViewController: demoViewController animated:YES];

storyboard下:

//指定是哪个storyboard下的哪个viewController

   UIStoryboard*  sb = [UIStoryboard storyboardWithName:@"MainStoryboard"  bundle:nil];

   UIViewController *demoViewController1 = [sb instantiateViewControllerWithIdentifier:@"viewControllerIdentifier"];    //在view controller的attribute inspector下设置

   [self.navigationController pushViewController: demoViewController1 animated:YES];

– popViewControllerAnimated:

[self.navigationControllerpopViewControllerAnimated:YES];

– popToRootViewControllerAnimated:

[self.navigationController popToRootViewControllerAnimated:YES];

– popToViewController:animated:

//跳转至链表中的某个位次

[self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:0] animated:YES];

//跳转至链表中的特点view controller

for (UIViewController *temp inself.navigationController.viewControllers) {

          if ([temp isKindOfClass:[你要跳转到的Controller class]]) {

             [self.navigationControllerpopToViewController:temp animated:YES];

          }

      }

(以上两个用法引自http://blog.csdn.net/hufeng825/article/details/7243823

 

经过细测,这种方法本身可以满足在链表中来回跳动且无内存泄露。


(支持用其他平台账号回应) 点点 新浪微博 人人网 豆瓣
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值