您的位置:首页 > 移动开发 > IOS开发

IOS_启动过程_项目文件_传统xib_加载view_空项目

2014-06-03 22:26 465 查看
H:/0720/01-Application和AppDelegate_main.m
//
//  main.m
//  01-Application和AppDelegate
//
//  Created by apple on 13-7-20.
//  Copyright (c) 2013年 itcast. All rights reserved.
//

#import <UIKit/UIKit.h>

#import "MJAppDelegate.h"

int main(int argc, char *argv[])
{
@autoreleasepool {
NSString *str = NSStringFromClass([MJAppDelegate class]);
NSLog(@"%@", str);

//NSString *str2 = NSStringFromClass([UIApplication class]);

/*
前2个参数: C语言标准
第3个参数:应用程序象征的类名(只能传UIApplication或其子类,
若为nil,默认就是UIApplication)
1个UIApplication对应1个应用程序,单例的~
还可以传UIApplication的子类
第4个参数:UIApplication代理的类名,负责加载storyboard文件,和监听app事件

*/
return UIApplicationMain(argc, argv, nil, str);
}
}

H:/0720/01-Application和AppDelegate_MJAppDelegate.h
//
//  MJAppDelegate.h
//  01-Application和AppDelegate
//
//  Created by apple on 13-7-20.
//  Copyright (c) 2013年 itcast. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface MJAppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;

@end

H:/0720/01-Application和AppDelegate_MJAppDelegate.m
//  MJAppDelegate.m
//  01-Application和AppDelegate
//  Created by apple on 13-7-20.
//  Copyright (c) 2013年 itcast. All rights reserved.
#import "MJAppDelegate.h"
/*
应用程序的代理,负责监听应用程序的生命变化
*/
@implementation MJAppDelegate
// ----------------首次启动,调用下面2个方法-----------------------------
#pragma mark 在应用程序启动完毕后调用(只会调用一次,第一次打开程序的时候才会调用)
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSLog(@"FinishLaunching");
// Override point for customization after application launch.
return YES;
}
#pragma mark 当app获得焦点的时候调用(已激活)
- (void)applicationDidBecomeActive:(UIApplication *)application
{
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
NSLog(@"BecomeActive");
}
// ----------------此时点击home键盘,会进入后台,调用下面两个方法-----------------------------
#pragma mark 当app失去焦点的时候调用(未激活)
- (void)applicationWillResignActive:(UIApplication *)application
{
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
NSLog(@"ResignActive");
}
#pragma mark 在app进入后台的时候调用
- (void)applicationDidEnterBackground:(UIApplication *)application
{
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
NSLog(@"EnterBackground");
}
// -----------------再次点击程序图标,进入前台,会调用下面2个方法(BecomeActive)-----------------------------

#pragma mark 在app进入前台的时候调用
- (void)applicationWillEnterForeground:(UIApplication *)application
{
NSLog(@"EnterForeground");
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}
#pragma mark 当app被关闭的时候会调用(前提条件:app在后台运行,而非休眠)
- (void)applicationWillTerminate:(UIApplication *)application
{
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
@end

H:/0720/01-Application和AppDelegate_MJViewController.h
//
//  MJViewController.h
//  01-Application和AppDelegate
//
//  Created by apple on 13-7-20.
//  Copyright (c) 2013年 itcast. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface MJViewController : UIViewController
- (IBAction)click;

@end

H:/0720/01-Application和AppDelegate_MJViewController.m
//  MJViewController.m
//  01-Application和AppDelegate
//  Created by apple on 13-7-20.
//  Copyright (c) 2013年 itcast. All rights reserved.
#import "MJViewController.h"
@interface MJViewController ()
@end
@implementation MJViewController

// 响应按钮点击,修改应用程序图标右上角的数字
- (IBAction)click {
// 只要涉及应用程序,就必须获得单例的UIApplication
UIApplication *app =  [UIApplication sharedApplication];
// 设置图标右上角的数字,若设置为0,则无显示
//app.applicationIconBadgeNumber = 5;
// 设置后,会显示屏幕顶部,网络图标正在打转,假象
//app.networkActivityIndicatorVisible = YES;
// 打电话\发短信\发邮件\打开safari浏览器
NSURL *url = [NSURL URLWithString:@"tel://10086"];
// 不支持,NSURL *url = [NSURL URLWithString:@"http://www.baidu.com"];
[app openURL:url];
}
@end

H:/0720/02-项目中的常见文件_main.m
//
//  main.m
//  02-项目中的常见文件
//
//  Created by apple on 13-7-20.
//  Copyright (c) 2013年 itcast. All rights reserved.
//

#import <UIKit/UIKit.h>

#import "MJAppDelegate.h"

int main(int argc, char *argv[])
{
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([MJAppDelegate class]));
}
}

H:/0720/02-项目中的常见文件_MJAppDelegate.h
//
//  MJAppDelegate.h
//  02-项目中的常见文件
//
//  Created by apple on 13-7-20.
//  Copyright (c) 2013年 itcast. All rights reserved.
//

@interface MJAppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;

@end

H:/0720/02-项目中的常见文件_MJAppDelegate.m
//  MJAppDelegate.m
//  02-项目中的常见文件
//  Created by apple on 13-7-20.
//  Copyright (c) 2013年 itcast. All rights reserved.
#import "MJAppDelegate.h"
@implementation MJAppDelegate
#pragma mark 程序加载完毕
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// 启动过程中,隐藏状态栏,全屏显示图片,启动加载完毕,显示状态栏
application.statusBarHidden = NO;
/*
Default.png   320x480 Iphone3
Default@2x.png  640x960 Iphone4
Default-568h@2x.png  640x1136 Iphone5
*/
// Override point for customization after application launch.
return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application
{
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}
- (void)applicationDidEnterBackground:(UIApplication *)application
{
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
- (void)applicationWillEnterForeground:(UIApplication *)application
{
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}
- (void)applicationDidBecomeActive:(UIApplication *)application
{
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
- (void)applicationWillTerminate:(UIApplication *)application
{
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
@end

H:/0720/02-项目中的常见文件_MJViewController.h
//
//  MJViewController.h
//  02-项目中的常见文件
//
//  Created by apple on 13-7-20.
//  Copyright (c) 2013年 itcast. All rights reserved.
//

@interface MJViewController : UIViewController
@property (weak, nonatomic) IBOutlet UIImageView *imageView;
- (IBAction)click;

@end

H:/0720/02-项目中的常见文件_MJViewController.m
//  MJViewController.m
//  02-项目中的常见文件
//  Created by apple on 13-7-20.
//  Copyright (c) 2013年 itcast. All rights reserved.
/*
工程文件介绍:
1,info.plist是一个字典,最重要的一个文件
它记载了app的所有基本信息,如果版本号,app名称,唯一标识等
改了字典中的bundle display name之后,还要clean+卸载app,重装,生效
2,infoPlist.strings 本地化相关 国际化 i18n
3,Prefix.pch文件,重要!!! .h头文件,用来被项目中所有其他的文件包含的,
包含了项目中全局性的宏定义和#import语句,
所有项目中的文件都可以访问并使用
例如:自定义Log函数
#define log(...) NSLog(__VA_ARGS__)
#define echo(...) NSLog(__VA_ARGS__)
#define print(...) NSLog(__VA_ARGS__)
#define var_dump(...) NSLog(__VA_ARGS__)
当项目最后发布的时候,注释掉后面的即可
#define log(...)  //NSLog(__VA_ARGS__)
当程序在调试姿态下系统自动定义宏DEBUG,真机不会定义改宏
所有,还有更加智能的方式:
#ifdef DEBUG
#define log(...) NSLog(__VA_ARGS__)
#else
#define log(...)
#endif
4,应用程序的时候,屏幕闪过的图片
Default.png   320x480 Iphone3
Default@2x.png  640x960 Iphone4
Default-568h@2x.png  640x1136 Iphone5
5,icon.png 软件桌面图标
-------------------------------------------------
程序完整启动过程:
1,点击app图标,执行main函数,执行UIApplicationMain函数
2,创建UIApplication对象,代理对象UIApplicationDelegate
3,开启事件循环,监听系统事件
4,加载程序完毕,调用代理的didFinishLanchWithOptions方法
5,下面是代理delegate的方法实现:
a,创建窗口对象
self.window=[[UIWindow alloc] initWithFrame...
b,创建控制器对象
self.viewController=[[MJViewController alloc]initWithNibName...
c,设置窗口的root控制器为上面的控制器对象
self.window.rootViewController=self.viewController
d,最后,使窗口变成主窗口,并可见
[self.window makeKeyAndVisible]

*/
#import "MJViewController.h"
@interface MJViewController ()
@end
@implementation MJViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.imageView.image = [UIImage imageNamed:@"0.png"];
int count = 10;
/*
#define MJLog(...)  NSLog(__VA_ARGS__)
*/
MJLog(@"count=%d", count);
//NSLog(@"count=%d", count);
MJLog(@"%d-----%d", count, 100);
// Do any additional setup after loading the view, typically from a nib.
}
- (IBAction)click {
NSLog(@"%@", [UIApplication sharedApplication].keyWindow);
NSLog(@"%@", self.view.superview);
}
@end

H:/0720/02-项目中的常见文件_Person.h
//
//  Person.h
//  02-项目中的常见文件
//
//  Created by apple on 13-7-20.
//  Copyright (c) 2013年 itcast. All rights reserved.
//

#import <Foundation/Foundation.h>

@interface Person : NSObject

@end

H:/0720/02-项目中的常见文件_Person.m
//
//  Person.m
//  02-项目中的常见文件
//
//  Created by apple on 13-7-20.
//  Copyright (c) 2013年 itcast. All rights reserved.
//

#import "Person.h"

@implementation Person

@end

H:/0720/03-传统xib的使用_main.m
//
//  main.m
//  03-传统xib的使用
//
//  Created by apple on 13-7-20.
//  Copyright (c) 2013年 itcast. All rights reserved.
//

#import <UIKit/UIKit.h>

#import "MJAppDelegate.h"

int main(int argc, char *argv[])
{
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([MJAppDelegate class]));
}
}

H:/0720/03-传统xib的使用_MJAppDelegate.h
//
//  MJAppDelegate.h
//  03-传统xib的使用
//
//  Created by apple on 13-7-20.
//  Copyright (c) 2013年 itcast. All rights reserved.
//

#import <UIKit/UIKit.h>

@class MJViewController;

@interface MJAppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;

@property (strong, nonatomic) MJViewController *viewController;

@end

H:/0720/03-传统xib的使用_MJAppDelegate.m
//
//  MJAppDelegate.m
//  03-传统xib的使用
//
//  Created by apple on 13-7-20.
//  Copyright (c) 2013年 itcast. All rights reserved.
//

#import "MJAppDelegate.h"

#import "MJViewController.h"

@implementation MJAppDelegate
//UIWindow *mywindow;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// 创建一个UIWindow
CGRect rect = [[UIScreen mainScreen] bounds];
self.window = [[UIWindow alloc] initWithFrame:rect];

self.window.backgroundColor = [UIColor redColor];

// 初始化第一个控制器
//self.viewController = [[MJViewController alloc] initWithNibName:@"MJViewController" bundle:nil];

// 设置窗口的根控制器
//self.window.rootViewController = self.viewController;
// 等窗口UIWindow显示的时候,就会把rootViewControoler的view添加到UIWindow上面去
// 相当于会执行下面的代码
//[self.window addSubview:self.viewController.view];

// 让窗口成为主窗口并且可见
[self.window makeKeyAndVisible];
// 一个程序中只能有一个主窗口,主窗口:能跟用户进行交互的窗口
// 主窗口里面的文本框才能正常输入文字

UIButton *btn = [UIButton buttonWithType:UIButtonTypeContactAdd];
//[btn addTarget:self action:<#(SEL)#> forControlEvents:<#(UIControlEvents)#>];
btn.center = CGPointMake(100, 100);
[self.window addSubview:btn];

/*
mywindow = [[UIWindow alloc] initWithFrame:CGRectMake(0, 100, 100, 100)];
mywindow.backgroundColor = [UIColor yellowColor];
[mywindow makeKeyAndVisible];*/
return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application
{
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application
{
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application
{
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end

H:/0720/03-传统xib的使用_MJViewController.h
//
//  MJViewController.h
//  03-传统xib的使用
//
//  Created by apple on 13-7-20.
//  Copyright (c) 2013年 itcast. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface MJViewController : UIViewController

@end

H:/0720/03-传统xib的使用_MJViewController.m
//
//  MJViewController.m
//  03-传统xib的使用
//
//  Created by apple on 13-7-20.
//  Copyright (c) 2013年 itcast. All rights reserved.
//

#import "MJViewController.h"

@interface MJViewController ()

@end

@implementation MJViewController

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

@end

H:/0720/04-控制器view的加载_MJAppDelegate.h
//  MJAppDelegate.h
//  04-控制器view的加载
//  Created by apple on 13-7-20.
//  Copyright (c) 2013年 itcast. All rights reserved.
#import <UIKit/UIKit.h>
@class MJViewController;
@interface MJAppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) MJViewController *viewController;
@end

H:/0720/04-控制器view的加载_MJAppDelegate.m
//  MJAppDelegate.m
//  04-控制器view的加载
//  Created by apple on 13-7-20.
//  Copyright (c) 2013年 itcast. All rights reserved.
#import "MJAppDelegate.h"
#import "MJViewController.h"
@implementation MJAppDelegate
/*
程序完整启动过程:
1,点击app图标,执行main函数,执行UIApplicationMain函数
2,创建UIApplication对象,代理对象UIApplicationDelegate
3,开启事件循环,监听系统事件
4,加载程序完毕,调用代理的didFinishLanchWithOptions方法
5,下面是代理delegate的方法实现:
a,创建窗口对象
self.window=[[UIWindow alloc] initWithFrame...
b,创建控制器对象
self.viewController=[[MJViewController alloc]initWithNibName...
c,设置窗口的root控制器为上面的控制器对象
self.window.rootViewController=self.viewController
d,最后,使窗口变成主窗口,并可见
[self.window makeKeyAndVisible]

*/
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// 为代理的成员赋值:创建窗口对象
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// 创建控制器(控制器的view是延时加载:用到时再加载)
self.viewController = [[MJViewController alloc] initWithNibName:@"MJViewController" bundle:nil];
//self.viewController.view.backgroundColor = [UIColor blueColor];
// 设置根控制器(没有用到根控制器的view),设置窗口的root控制器为上面的控制器对象
self.window.rootViewController = self.viewController;
/*
1.控制器MJViewController的view是延迟加载的
2.用到view时,就会调用控制器的loadView方法加载view
3.loadView加载view的默认过程(UIViewController的默认实现)
1> 如果nibName有值,就会加载对应的xib文件来创建view
2> 如果nibName没有值
1) 优先加载MJView.xib文件来创建view
2) 否则,加载MJViewController.xib文件来创建view
3) 如果没有找到上面所述的xib文件,就会用代码创建一个黑色的view
*/
[self.window makeKeyAndVisible];
return YES;
}
@end

H:/0720/04-控制器view的加载_MJViewController.h
//  MJViewController.h
//  04-控制器view的加载
//  Created by apple on 13-7-20.
//  Copyright (c) 2013年 itcast. All rights reserved.
/*
掌握:
1.loadView方法的使用
2.veiwDidLoad方法的调用时刻,用到view的时候才加载,延时加载,懒汉式加载
3.控制器的view有2种创建方式:
1> xib
2> 代码(重写loadView方法)
*/
#import <UIKit/UIKit.h>
@interface MJViewController : UIViewController
@end

H:/0720/04-控制器view的加载_MJViewController.m
//  MJViewController.m
//  04-控制器view的加载
/*
1.控制器MJViewController的view是延迟加载的
2.用到view时,才会调用控制器的loadView方法加载view
3.loadView加载view的默认过程(UIViewController的默认实现)
1> 如果nibName有值,就会加载对应的xib文件来创建view
2> 如果nibName没有值
1) 优先加载MJView.xib文件来创建view
2) 否则,加载MJViewController.xib文件来创建view
3) 如果没有找到上面所述的xib文件,就会用代码创建一个黑色的view
3> 如果控制器loadview被覆盖,而不做任何事情,则不会加载任何的view
- (void)loadView
{
}

*/
#import "MJViewController.h"
@interface MJViewController ()
@end
@implementation MJViewController
/*
控制器的LoadView方法是用来加载view的,
如果像下面这样被覆盖了,则不会加载任何view
- (void)loadView
{
NSLog(@"loadView");
}*/
#pragma mark 自定义view
/*
- (void)loadView
{
// 当我们要自定义控制器里面的view时,就不应该再调用super的loadView了
因为父类的loadView会执行下列操作,加载默认的view对象,这样就不是想要的自定义的view了

父类loadView加载view的默认过程(MJView Controller的默认实现)
1> 如果nibName有值,就会加载对应的xib文件来创建view
2> 如果nibName没有值
1) 优先加载MJView.xib文件来创建view(名字和控制器前面一样的xib)
2) 否则,加载MJViewController.xib文件来创建view(名字和控制器同名的xib)
3) 如果没有找到上面所述的xib文件,就会用loadview方法默认创建一个黑色的view
3> 如果控制器loadview被覆盖,而不做任何事情,则不会加载任何的view
- (void)loadView
{
}
4> 当我们想要自定义view时,重写loadView,且不必在里面调用super的loadView
5> 在loadView方法里面,使用self.view.frame会造成死循环
原因,第1次用到了view,才会加载view,即,会调用控制器的loadView方法,
这不就是死循环了么

// 死循环,右边self.view.frame要第1次获取控制器的view,会来到自身loadView方法....
//self.view = [[UIScrollView alloc] initWithFrame:self.view.frame];

// 模板代码:取得最适合控制器的view的frame
CGRect frame = [UIScreen mainScreen].applicationFrame;
self.view = [[UIScrollView alloc] initWithFrame:frame];
self.view.backgroundColor = [UIColor yellowColor];
}*/
#pragma mark view loaded 加载view的时刻,用到时才加载,延时加载,懒汉式
- (void)viewDidLoad
{
[super viewDidLoad];
// 上面的LoadView方法完成后,在本方法中,才可以初始化子控件,填充数据呀等
}
@end

H:/0720/05-空项目_FirstViewController.h
//
//  FirstViewController.h
//  05-空项目
//
//  Created by apple on 13-7-20.
//  Copyright (c) 2013年 itcast. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface FirstViewController : UIViewController

@end

H:/0720/05-空项目_FirstViewController.m
//  FirstViewController.m
//  05-空项目
/*
Xcode,新建,一个empty project
1,这时候,只会有一个delegate.h/.m
依然可以正常运行,界面白色
其实是delegate里面的UIWindow
2,新建一个OC class,继承自UIViewController
并且勾选 with xib 创建界面
注:3种方式,代码,storyboard,xib
3,生成FirstViewController.h/.m/.xib
4,在MJAppDelegate.m文件中导入FirstViewController.h
设置窗口的根控制器为新建的FirstViewController

*/

#import "FirstViewController.h"
@interface FirstViewController ()
@end
@implementation FirstViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
@end

H:/0720/05-空项目_main.m
//
//  main.m
//  05-空项目
//
//  Created by apple on 13-7-20.
//  Copyright (c) 2013年 itcast. All rights reserved.
//

#import <UIKit/UIKit.h>

#import "MJAppDelegate.h"

int main(int argc, char *argv[])
{
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([MJAppDelegate class]));
}
}

H:/0720/05-空项目_MJAppDelegate.h
//
//  MJAppDelegate.h
//  05-空项目
//
//  Created by apple on 13-7-20.
//  Copyright (c) 2013年 itcast. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface MJAppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;

@end

H:/0720/05-空项目_MJAppDelegate.m
//
//  MJAppDelegate.m
//  05-空项目
//
//  Created by apple on 13-7-20.
//  Copyright (c) 2013年 itcast. All rights reserved.
/*
Xcode,新建,一个empty project
1,这时候,只会有一个delegate.h/.m
依然可以正常运行,界面白色
其实是delegate里面的UIWindow
2,新建一个OC class,继承自UIViewController
并且勾选 with xib 创建界面
注:3种方式,代码,storyboard,xib
3,生成FirstViewController.h/.m/.xib
4,在MJAppDelegate.m文件中导入FirstViewController.h
设置窗口的根控制器为新建的FirstViewController

*/

#import "MJAppDelegate.h"
#import "FirstViewController.h"

@implementation MJAppDelegate

- (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.rootViewController = [[FirstViewController alloc] init];
// 显示窗口
[self.window makeKeyAndVisible];
return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application
{
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application
{
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application
{
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end

H:/0720/06-空项目_FirstViewController.h
//
//  FirstViewController.h
//  06-空项目2
//
//  Created by apple on 13-7-20.
//  Copyright (c) 2013年 itcast. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface FirstViewController : UIViewController

@end

H:/0720/06-空项目_FirstViewController.m
//
//  FirstViewController.m
//  06-空项目2
//
//  Created by apple on 13-7-20.
//  Copyright (c) 2013年 itcast. All rights reserved.
//

#import "FirstViewController.h"

@interface FirstViewController ()

@end

@implementation FirstViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

@end

H:/0720/06-空项目_main.m
//
//  main.m
//  06-空项目2
//
//  Created by apple on 13-7-20.
//  Copyright (c) 2013年 itcast. All rights reserved.
//

#import <UIKit/UIKit.h>

#import "MJAppDelegate.h"

int main(int argc, char *argv[])
{
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, nil);
}
}

H:/0720/06-空项目_MJAppDelegate.h
//
//  MJAppDelegate.h
//  06-空项目2
//
//  Created by apple on 13-7-20.
//  Copyright (c) 2013年 itcast. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface MJAppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) IBOutlet UIWindow *window;

@end

H:/0720/06-空项目_MJAppDelegate.m
//
//  MJAppDelegate.m
//  06-空项目2
//
//  Created by apple on 13-7-20.
//  Copyright (c) 2013年 itcast. All rights reserved.
//

#import "MJAppDelegate.h"
#import "FirstViewController.h"

@implementation MJAppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//NSLog(@"%@", self.window);

//[self.window makeKeyAndVisible];
return YES;
}

/*
- (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.rootViewController = [[FirstViewController alloc] init];
[self.window makeKeyAndVisible];
return YES;
}*/

- (void)applicationWillResignActive:(UIApplication *)application
{
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application
{
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application
{
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐