1.AppDelegate.h
定义一个UINavigationController
#import <UIKit/UIKit.h>
#import "MainViewController.h"
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) UINavigationController *navigationCotroller;
@end
2.AppDelegate.m
#import "AppDelegate.h"
@interface AppDelegate ()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc]initWithFrame:[[UIScreen mainScreen]bounds]];//实例化window
MainViewController *mainViewController = [[MainViewController alloc]init];//实例化mainView控制器
//把mainView控制器放到navigationController的方法中,使之成为根控制器
_navigationCotroller = [[UINavigationController alloc] initWithRootViewController:mainViewController];
[_window addSubview:_navigationCotroller.view];//window中加载导航控制器的view
[self.window makeKeyAndVisible];//视图可见
return YES;
}
3.mainViewController.m
设置按钮的页面,按钮触发的方法中,调用AppDelegate中的导航控制器的pushViewController方法,实现页面跳转(自动生成有返回健的页面)。
按钮触发的方法:
[_logonBtn addTarget:self action:@selector(loginClick:) forControlEvents:UIControlEventTouchUpInside];
页面跳转:
-(void)loginClick:(id)sender{
LogonViewController *logonView = [[LogonViewController alloc]init];
AppDelegate *myDelete = [[UIApplication sharedApplication]delegate];
[myDelete.navigationCotroller pushViewController:logonView animated:YES];
}