本学主要记录代码控制视图及控件 拖控件到xib中不进行记录(因为听同事说拖控件开发会对项目不好控制等等) 。声明在此之前最好看一下 oc基础知识。在官网找到一点关于ios基础介绍的(https://developer.apple.com/library/ios/#referencelibrary/GettingStarted/RoadMapiOSCh/chapters/WriteObjective-CCode/WriteObjective-CCode/WriteObjective-CCode.html https://developer.apple.com/library/ios/navigation/#section=Resource%20Types&topic=Getting%20Started)
(一)下载并安装xcode (App Store、iTunes或者developer.apple.com下载)
(二)打开xcode 创建项目
1.选择 Application》 Single View Application 单视图应用程序
2. 产品名(Product Name):stady1;Organization name:pin..; Company Identifier :pin.. ; Devices : iphone》Next(本学习不考虑故事板及自动释放资源功能 为了更好控制视图及控件释放)
3.项目大概结构 一个项目就创建成功了 可以run一下 是一个空白的页面
(三)先开始试着认识创建好的项目中自动生成文件
1.Supporting Files 目录中有个 main.m 文件 从代码一看便知是主程序入口 并且引用 AppDelegate.h 类
#import <UIKit/UIKit.h> #import "AppDelegate.h" int main(int argc, char *argv[]) { @autoreleasepool { return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); } }
2.看 AppDeletegate.h有初始化有属性ViewController
#import <UIKit/UIKit.h> @class ViewController; @interface AppDelegate : UIResponder <UIApplicationDelegate> @property (strong, nonatomic) UIWindow *window; @property (strong, nonatomic) ViewController *viewController; @end
#import "AppDelegate.h" #import "ViewController.h" @implementation AppDelegate - (void)dealloc { [_window release]; [_viewController release]; [super dealloc]; } - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; // Override point for customization after application launch. self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil] autorelease]; self.window.rootViewController = self.viewController; [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
4. ViewController.h文件
#import <UIKit/UIKit.h> @interface ViewController : UIViewController @end
#import "ViewController.h" @interface ViewController () @end @implementation ViewController - (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
(四)总结:从这个单视图项目中可以很明显的看出 M-V-C 模式 清楚javaEE开发的很清楚这个情况 具体mvc模式不多说