#import "AppDelegate.h"
#import "MainViewController.h"
@interface AppDelegate ()
@end
@implementation AppDelegate
- (void)dealloc
{
[_window release];
[super dealloc];
}
- (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];
[self.window makeKeyAndVisible];
[_window release];
// UIViewController的使用
// 1.UIViewController的一个对象代表一个页面,负责处理一部分功能(登入页面,注册页面,找回密码页面...分别就是不同的viewController)
// 2.UIViewController是一个抽象类,即,不能直接使用,如果要使用需要创建它的子类才能使用
MainViewController *mainVC = [[MainViewController alloc] init];
// 给window设置一个根视图控制器,作为启动之后默认显示的界面
self.window.rootViewController = mainVC;
[mainVC release];
return YES;
}
#import "MainViewController.h"
#import "SecondViewController.h"
@interface MainViewController ()
@end
@implementation MainViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
// 以后的视图创建代码写在这里
// 每一个视图控制器都自带一个view,用来添加其他视图
self.view.backgroundColor = [UIColor redColor];
UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
button.backgroundColor = [UIColor yellowColor];
button.frame = CGRectMake(20, 20, 335, 40);
[button setTitle:@"button" forState:UIControlStateNormal];
[button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
}
- (void)buttonAction:(UIButton *)btn
{
NSLog(@"点击");
// 弹出新的一个页面(viewController)
// 1.创建新页面的对象
SecondViewController *secondVC = [[SecondViewController alloc] init];
// 2.弹出(模态)
// 参数1: 要弹出新页面(viewController)
// 参数2: 是否需要动画效果
// 参数3: 弹出完毕之后执行的代码
//secondVC.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentViewController:secondVC animated:YES completion:^{
NSLog(@"弹出完毕");
}];
// 3. 内存管理
[secondVC release];
}
#import "SecondViewController.h"
@interface SecondViewController ()
@end
@implementation SecondViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = [UIColor blueColor];
UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
button.backgroundColor = [UIColor yellowColor];
button.frame = CGRectMake(20, 20, 335, 40);
[button setTitle:@"返回" forState:UIControlStateNormal];
[button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
}
- (void)buttonAction:(UIButton *)btn
{
// 在第二个页面点击返回
[self dismissViewControllerAnimated:YES completion:^{
}];
}