您当前的位置: 首页 > 

手动操作导航控制器的子视图控制器的数组

发布时间:2016-02-28 10:15:19 ,浏览量:0

大熊猫猪·侯佩原创或翻译作品.欢迎转载,转载请注明出处. 如果觉得写的不好请多提意见,如果觉得不错请多多支持点赞.谢谢! hopy ;)

免责申明:本博客提供的所有翻译文章原稿均来自互联网,仅供学习交流之用,请勿进行商业用途。同时,转载时不要移除本申明。如产生任何纠纷,均与本博客所有人、发表该翻译稿之人无任何关系。谢谢合作!

你可能希望直接操作与特定导航控制器相关的子视图控制器的数组.

你可以使用UINavigationController的viewControllers属性修改其相关联的子视图控制器:

- (void) goBack{ /* Get the current array of View Controllers */ NSArray *currentControllers = self.navigationController.viewControllers; /* Create a mutable array out of this array */ NSMutableArray *newControllers = [NSMutableArray arrayWithArray:currentControllers]; /* Remove the last object from the array */ [newControllers removeLastObject]; /* Assign this array to the Navigation Controller */ self.navigationController.viewControllers = newControllers;
    }

你可以任何视图控制器中调用该方法去弹出继承体系中最后(最后push入的,猫猪注)的导航控制器的子视图控制器.

UINavigationController类的实例都持有一个数组对象,其中每一个元素皆为一个UIViewController对象.在获取到该数组之后,你可以以你希望的任何方式手动操作该数组.比如说,你可以删除该继承体系数组中的一个视图控制器.

但是直接操作这个UIViewController的数组并不会呈现给用户动画效果,如果你希望操作动画化,可以使用UINavigationController类的setViewControllers:animated:方法,代码如下:

- (void) goBack{ /* Get the current array of View Controllers */ NSArray *currentControllers = self.navigationController.viewControllers; /* Create a mutable array out of this array */ NSMutableArray *newControllers = [NSMutableArray arrayWithArray:currentControllers]; /* Remove the last object from the array */ [newControllers removeLastObject]; /* Assign this array to the Navigation Controller with animation */ [self.navigationController setViewControllers:newControllers
                                             animated:YES];
}
关注
打赏
1688896170
查看更多评论

暂无认证

  • 0浏览

    0关注

    108697博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文
立即登录/注册

微信扫码登录

0.0463s