002.HelloWorld 单视图工程

来源:互联网 发布:mysql数据库接口 编辑:程序博客网 时间:2024/06/07 04:00
-------------  ViewController.m -------------
#import"ViewController.h"

@interfaceViewController()
@end

@implementationViewController
- (
void)viewDidLoad
{
     [superviewDidLoad];  
     inta = 1;
     NSLog(@"%d", a);
}
- (
void)didReceiveMemoryWarning
{
     [superdidReceiveMemoryWarning];
}
@end

一、编写本节代码的具体步骤:
1.打开Xcode。
2.点击Create a new Xcode project。
3.选择iOS下的Application,然后点击Single View Application,点next。
4.填写项目名称等,选择Language是OC,Devices是iPhone,不要勾选Use Core Data,点next。
5.选择文件储存目录,不要勾选Create Git repository on My Mac,点Create。
6.在左侧导航栏中选中ViewController.m文件,在右侧代码编辑区,编写代码如上。

二、本节代码涉及到的知识点:
1.为了提高代码的可读性,我们把代码源文件分为.h文件和.m文件,分别用来存放声明与实现。
2.在逻辑上,本节代码主要分为两个部分,分别是 @interface部分与 @implementation部分。
   @interface部分        用来声明类的成员变量和方法。
  @implementation部分   用来实现该类的方法。
3.ViewController 继承自 UIViewController,即视图控制器,是系统提供给我们的一个类。
4.ViewController 默认有两个方法,分别是 viewDidLoad 和 didReceiveMemoryWarning。
5.super 是OC中的一个关键字,使子类可以调用父类的方法。
0 0
原创粉丝点击