天天看點

IOS_啟動過程_項目檔案_傳統xib_加載view_空項目

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
    [email protected]  640x960 Iphone4
    [email protected]  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
		[email protected]  640x960 Iphone4
		[email protected]  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