标签:
一 创建控制器
第1种方式 通过代码控制器
HKUIViewController.h
#import <UIKit/UIKit.h>
@interface HKUIViewController : UIViewController
@end
HKUIViewController.m
#import "HKUIViewController.h" @implementation HKUIViewController @end
AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[UIWindow alloc]init] ; HKUIViewController * hkvc = [[HKUIViewController alloc]init]; hkvc.view.backgroundColor = [UIColor redColor]; self.window.rootViewController = hkvc; [self.window makeKeyAndVisible]; return YES; }
第2种方式: 通过storyboard加载控制器。
1) XCode创建storyboard
Xcode -> iOS -> User interface -> Storyboard 新建一个名为 Test.storyboard文件。
2) 设置Test.storyboard为 initial View Controller
勾选中 is initial View Controller.
3)拖拽一个 View Controller到 Test.storyboard中。
设置他的class为 HKUIViewController。
AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[UIWindow alloc]init] ; UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Test" bundle:nil]; HKUIViewController * hkvc = [storyboard instantiateInitialViewController]; self.window.rootViewController = hkvc; [self.window makeKeyAndVisible]; return YES; }
也可以通过表示加载控制器。
在 Test.storyboard中 identity设置Storyboard ID为 switch。
AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[UIWindow alloc]init] ; UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Test" bundle:nil]; // HKUIViewController * hkvc = [storyboard instantiateInitialViewController]; HKUIViewController *hkvc = [storyboard instantiateViewControllerWithIdentifier:@"switch"]; self.window.rootViewController = hkvc; [self.window makeKeyAndVisible]; return YES; }
知识点:
commond + n 新建一个storyboard
标签:
原文地址:http://www.cnblogs.com/wangshuo1/p/5469813.html