navigation pushController pushViewController 多次跳转后怎么返回

「小提示:图片加载慢就多刷新刷新哦!」
iOS 导航控制器返回栈中的某一控制器
怪哈哈,ACG游戏,ACG和谐区,足控福利,里番漫画,里番动漫,里番库,里番吧,本子库
& & & & & & & & & & & & & & & & & & &&#import &UIKit/UIKit.h&@interface AppDelegate : UIResponder &UIApplicationDelegate&@property (strong, nonatomic) UIWindow *@end#import &AppDelegate.h&#import &FirstViewController.h&@interface AppDelegate ()@end@implementation AppDelegate- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
& &self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; & &// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor]; & &//初始化控制器
UINavigationController *navi = [[UINavigationController alloc] initWithRootViewController:[[FirstViewController alloc] init]];
& &self.window.rootViewController =
& &[self.window makeKeyAndVisible]; & &return YES;
}@end#import &UIKit/UIKit.h&@interface FirstViewController : UIViewController@end#import &FirstViewController.h&#import &SecondViewController.h&@interface FirstViewController ()@end@implementation FirstViewController- (void)viewDidLoad {
& &[super viewDidLoad];
& &self.view.backgroundColor = [UIColor redColor];
& &self.title = @&第一个控制器&;
& &UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
& &button.frame = CGRectMake(70, 100, 180, 45);
& &button.backgroundColor = [UIColor whiteColor];
& &[button setTitle:@&跳到第二个控制器& forState:0];
& &[button setTitleColor:[UIColor greenColor] forState:0];
& &[button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
& &[self.view addSubview:button];
}- (void)buttonAction:(UIButton *)sender{
& &[self.navigationController pushViewController:[[SecondViewController alloc] init] animated:YES];
}- (void)didReceiveMemoryWarning {
& &[super didReceiveMemoryWarning]; & &// Dispose of any resources that can be recreated.}@end#import &UIKit/UIKit.h&@interface SecondViewController : UIViewController@end#import &SecondViewController.h&#import &ThirdViewController.h&@interface SecondViewController ()@end@implementation SecondViewController- (void)viewDidLoad {
& &[super viewDidLoad];
& &self.view.backgroundColor = [UIColor orangeColor];
& &self.title = @&第二个控制器&;
& &UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
& &button.frame = CGRectMake(70, 100, 180, 45);
& &button.backgroundColor = [UIColor whiteColor];
& &[button setTitle:@&跳到第三个控制器& forState:0];
& &[button setTitleColor:[UIColor greenColor] forState:0];
& &[button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
& &[self.view addSubview:button];
}- (void)buttonAction:(UIButton *)sender{
& &[self.navigationController pushViewController:[[ThirdViewController alloc] init] animated:YES];
}- (void)didReceiveMemoryWarning {
& &[super didReceiveMemoryWarning]; & &// Dispose of any resources that can be recreated.}@end#import &UIKit/UIKit.h&@interface ThirdViewController : UIViewController@end#import &ThirdViewController.h&#import &FourthViewController.h&@interface ThirdViewController ()@end@implementation ThirdViewController- (void)viewDidLoad {
& &[super viewDidLoad];
& &self.title = @&第三个控制器&;
& &self.view.backgroundColor = [UIColor yellowColor];
& &UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
& &button.frame = CGRectMake(70, 100, 180, 45);
& &button.backgroundColor = [UIColor whiteColor];
& &[button setTitle:@&跳到第四个控制器& forState:0];
& &[button setTitleColor:[UIColor greenColor] forState:0];
& &[button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
& &[self.view addSubview:button];
}- (void)buttonAction:(UIButton *)sender{
& &[self.navigationController pushViewController:[[FourthViewController alloc] init] animated:YES];
}- (void)didReceiveMemoryWarning {
& &[super didReceiveMemoryWarning]; & &// Dispose of any resources that can be recreated.}@end#import &UIKit/UIKit.h&@interface FourthViewController : UIViewController@end#import &FourthViewController.h&#import &FifthViewController.h&@interface FourthViewController ()@end@implementation FourthViewController- (void)viewDidLoad {
& &[super viewDidLoad];
& &self.title = @&第四个控制器&;
& &self.view.backgroundColor = [UIColor greenColor];
& &UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
& &button.frame = CGRectMake(70, 100, 180, 45);
& &button.backgroundColor = [UIColor whiteColor];
& &[button setTitle:@&跳到第五个控制器& forState:0];
& &[button setTitleColor:[UIColor greenColor] forState:0];
& &[button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
& &[self.view addSubview:button];
}- (void)buttonAction:(UIButton *)sender{
& &[self.navigationController pushViewController:[[FifthViewController alloc] init] animated:YES];
}- (void)didReceiveMemoryWarning {
& &[super didReceiveMemoryWarning]; & &// Dispose of any resources that can be recreated.}@end#import &UIKit/UIKit.h&@interface FifthViewController : UIViewController@end#import &FifthViewController.h&#import &ThirdViewController.h&@interface FifthViewController ()@end@implementation FifthViewController- (void)viewDidLoad {
& &[super viewDidLoad];
& &self.title = @&第五个控制器&;
& &self.view.backgroundColor = [UIColor blueColor];
& &[self setupViews];
* &初始化视图 */- (void)setupViews{
& &[self initializeButtonWithFrame:CGRectMake(70, 100, 180, 45) tag:1000 title:@&返回第一个控制器&];
& &[self initializeButtonWithFrame:CGRectMake(70, 160, 180, 45) tag:1001 title:@&返回第二个控制器&];
& &[self initializeButtonWithFrame:CGRectMake(70, 220, 180, 45) tag:1002 title:@&返回第三个控制器&];
& &[self initializeButtonWithFrame:CGRectMake(70, 280, 180, 45) tag:1003 title:@&返回第四个控制器&];
* &初始化button
* &@param frame 尺寸
* &@param tag & 标签
* &@param title button的标题 */- (void)initializeButtonWithFrame:(CGRect)frame tag:(NSInteger)tag title:(NSString *)title {
& &UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
& &button.frame =
& &button.tag =
& &button.backgroundColor = [UIColor orangeColor];
& &[button setTitle:title forState:0];
& &[button setTitleColor:[UIColor whiteColor] forState:0];
& &[button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
& &[self.view addSubview:button];
* &button触发的事件 */- (void)buttonAction:(UIButton *)sender{// & & 在self.navigationController.viewControllers数组(的栈)中找到相应的控制器
UIViewController *viewController = self.navigationController.viewControllers[sender.tag - 1000];
& &[self.navigationController popToViewController:viewController animated:YES]; & &
& &//跳到某一控制器 & &//遍历导航控制器(栈)中的控制器// & &for (UIViewController *controller in self.navigationController.viewControllers) {//
// 找到相应的控制器// & & & &if ([controller isKindOfClass:[ThirdViewController class]]) {//
//跳转到该控制器// & & & & & &[self.navigationController popToViewController:controller animated:YES];// & & & &}// & &}}- (void)didReceiveMemoryWarning {
& &[super didReceiveMemoryWarning]; & &// Dispose of any resources that can be recreated.}@end
怪哈哈,ACG游戏,ACG和谐区,足控福利,里番漫画,里番动漫,里番库,里番吧,本子库
向大家推荐一个好玩有趣的微信公众号 ~ ~
注意啦!!!注意啦!!!
二次元★ACG游戏·美女控·技术宅资源分享社区★ /
怪哈哈,ACG游戏,ACG和谐区,足控福利,里番漫画,里番动漫,里番库,里番吧,本子库
本文链接地址:
网友评论 (0 条评论)
:) &微信头像(这里有超级棒棒哒的微信头像哦~~)
:) &美女校花(各种乱七八糟的校花都在这里~~)
:) &美女自拍(好多漂亮美眉在这里扑打扑打~~)
:) &搞笑图文(绝对让你笑掉大牙的内涵段子~~)
本站文字和图片均为严格审查筛选收藏,均收集整理于互联网,其著作权归原作者所有,如果有侵犯您权利的照片,请来信告知,我们将及时撤销相应文字和图片。
业务合作请加QQ:
Copyright @ 怪哈哈网 All Rights Reserved.如何让UIView中的Button点击之后跳转到另一个ViewController上去,ViewController上也有一个按钮 可以返回
来源:博客园
第一种方法:如果使用导航 第一个按钮方法: [self.navigationController pushViewController:secondVC animated:YES]; 第二个按钮方法: [self.navigationController popViewControllerAnimated:YES]; 第二种方法:如果使用模态 第一个按钮方法: [self presentViewController:secondVC animated:YES completion:nil]; 第二个按钮方法: [self dismissViewControllerAnimated:YES completion:nil];
免责声明:本站部分内容、图片、文字、视频等来自于互联网,仅供大家学习与交流。相关内容如涉嫌侵犯您的知识产权或其他合法权益,请向本站发送有效通知,我们会及时处理。反馈邮箱&&&&。
学生服务号
在线咨询,奖学金返现,名师点评,等你来互动navigationController pushViewController 多次跳转后怎么返回 - 博客频道 - CSDN.NET
文艺青年好像不是我
文艺的屌丝
分类:IOS入门学习iOS
关于ios中 viewcontroller的跳转问题,其中有一种方式是采用navigationController pushViewController 的方法,比如我从主页面跳转到了一级页面,又从一级页面跳转到了二级页面,然后从二级页面跳转到了三级页面,依次类推。,如果一级一级的返回我知道是没有问题的,调用navigationController&popViewControllerAnimated就行了。。但是某些情况下我可能想要马上回到主页面,而不是一级一级的返回(如果有很多层会很累的),那该怎么办呢?
返回根页面vc用 :
[self.navigationController popToRootViewController
返回指定的某个vc用下面(通过index定位)&
[self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:2]
animated:YES];
或(通过class定位)
(UIViewController *controller in self.navigationController.viewControllers) {
([controller isKindOfClass:[你要跳转到的Controller class]])
&&&&&&&&[self.navigationController
popToViewController:controller animated:YES];
排名:千里之外
(18)(2)(3)(3)(20)(13)(1)(5)(9)navigationController pushViewController 多次跳转后怎么返回_百度知道扫描二维码,关注牛客网
下载牛客APP,随时随地刷题
浙ICP备号-2
扫一扫,把题目装进口袋

我要回帖

更多关于 pushnavigationitem 的文章

 

随机推荐