你好,歡迎來到IOS教程網

 Ios教程網 >> IOS編程開發 >> IOS開發綜合 >> IOS開發(6)之UIViewController

IOS開發(6)之UIViewController

編輯:IOS開發綜合

1 前言
IOS開發遵循MVC模型,即模型-視圖-控制器。

視圖是展現給用戶的東西;模型是App管理的數據,也是App引擎的另一種叫法;控制器則是連接模型和視圖的橋梁。今天主要介紹一下,在新建跟視圖的ViewController時候,帶nib文件和不帶nib文件的區別。

2 UIViewController使用
上delegate的代碼

.h文件


[plain]
#import <UIKit/UIKit.h> 
#import "RootViewController.h" 
#import "ZYRootViewController.h" 
 
@interface ZYAppDelegate : UIResponder <UIApplicationDelegate> 
 
@property (strong, nonatomic) UIWindow *window; 
//@property (strong, nonatomic) RootViewController *rootViewController; 
@property (strong, nonatomic) ZYRootViewController *rootViewController; 
 
@end 

#import <UIKit/UIKit.h>
#import "RootViewController.h"
#import "ZYRootViewController.h"

@interface ZYAppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;
//@property (strong, nonatomic) RootViewController *rootViewController;
@property (strong, nonatomic) ZYRootViewController *rootViewController;

@end
.m文件


[plain]
@synthesize window = _window; 
@synthesize rootViewController; 
 
- (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];//去掉背景色方便顯示rootView 
    [self.window makeKeyAndVisible]; 
//    self.rootViewController = [[RootViewController alloc] initWithNibName:nil bundle:NULL];//無nib文件方式 
    self.rootViewController = [[ZYRootViewController alloc] initWithNibName:@"ZYRootViewController" bundle:NULL];//有nib文件方式 
    [self.window addSubview:self.rootViewController.view]; 
    return YES; 

@synthesize window = _window;
@synthesize rootViewController;

- (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];//去掉背景色方便顯示rootView
    [self.window makeKeyAndVisible];
//    self.rootViewController = [[RootViewController alloc] initWithNibName:nil bundle:NULL];//無nib文件方式
    self.rootViewController = [[ZYRootViewController alloc] initWithNibName:@"ZYRootViewController" bundle:NULL];//有nib文件方式
    [self.window addSubview:self.rootViewController.view];
    return YES;
}
運行結果:

 \
 


 

  1. 上一頁:
  2. 下一頁:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © Ios教程網 All Rights Reserved