hello,world不使用ARC
main.m
//
// main.m
// Hello
//
// Created by lishujun on 14-8-28.
// Copyright (c) 2014年 lishujun. All rights reserved.
// #import <UIKit/UIKit.h> // 视图控制器对象
@interface HelloWorldViewController : UIViewController
@end @implementation HelloWorldViewController -(void) loadView
{
/*
self.view = contentView;
[self setView contentView];
等价,设置属性其实是调用set方法
*/ //创建视图对象
UIView *contentView = [[UIView alloc]initWithFrame:[[UIScreen mainScreen] applicationFrame]];
NSLog(@"new contentView : %d", [contentView retainCount]); // new contentView : 1
contentView.backgroundColor = [UIColor lightGrayColor];
NSLog(@"set contentView : %d", [contentView retainCount]); // set contentView : 1
[self setView: contentView];
NSLog(@"add contentView : %d", [contentView retainCount]); // add contentView : 2 //创建label对象
UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0.0, 0.0, 320.0, 30.0)];
NSLog(@"new label : %d", [label retainCount]); // new label : 1
label.text = @"Hello World";
label.center = contentView.center;
label.textAlignment = UITextAlignmentCenter;
label.backgroundColor = [UIColor clearColor];
label.textColor = [UIColor redColor];
NSLog(@"set label : %d", [label retainCount]); // set label : 1 //在视图上添加label
[contentView addSubview:label];
NSLog(@"add label : %d", [label retainCount]); // add label : 2
[label release];
NSLog(@"release label : %d", [label retainCount]); // release label : 1 } @end // 委托对象
@interface HelloWorldAppDelegate : NSObject <UIApplicationDelegate>
{
IBOutlet UIWindow *window;
} @property (nonatomic, retain) UIWindow *window;
@property (nonatomic, retain) HelloWorldViewController *viewController;
//window 必须声明为属性,声明为局部变量则无法绘制视图,显示为黑屏
//apple 官方文档把viewController也声明为属性了
@end @implementation HelloWorldAppDelegate @synthesize window;
@synthesize viewController; -(void) applicationDidFinishLaunching:(UIApplication *)application
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen]bounds]];
self.viewController = [[HelloWorldViewController alloc]init];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
} @end // 程序入口
int main(int argc, char * argv[])
{
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, @"HelloWorldAppDelegate");
}
}
输出:
2014-08-30 11:47:30.980 HelloNOARC[562:60b] new contentView : 1
2014-08-30 11:47:30.983 HelloNOARC[562:60b] set contentView : 1
2014-08-30 11:47:30.984 HelloNOARC[562:60b] add contentView : 2
2014-08-30 11:47:30.985 HelloNOARC[562:60b] new label : 1
2014-08-30 11:47:30.986 HelloNOARC[562:60b] set label : 1
2014-08-30 11:47:30.986 HelloNOARC[562:60b] add label : 2
2014-08-30 11:47:30.987 HelloNOARC[562:60b] release label : 1
hello,world不使用ARC的更多相关文章
- Convert BSpline Curve to Arc Spline in OpenCASCADE
Convert BSpline Curve to Arc Spline in OpenCASCADE eryar@163.com Abstract. The paper based on OpenCA ...
- 黑马程序员——ARC机制总结和用ARC建立模型
ARC 全称:Automatic Reference Counting 使用ARC 只需要在建立一个新的项目的时候把 下面的√打上 Xcode5以后都会默认建议开发者使用ARC机制 新的项目中如果有部 ...
- JSONKit在项目中使用设置(ARC与方法更新)
在项目中经常会遇到解析json的情况,如果有同学想要解析JSON,那么JSONKit可以是一个不错的选择. git中JSONKit 的地址为:https://github.com/johnezang/ ...
- MRC迁移ARC之__block
今日帮着同事把老项目从MRC迁移至ARC,大部分工作无非是删除release,[super dealloc]等方法,只要关闭了MRC编译选项后,编译器能自动帮你检查,block就有一些不一样了,发现许 ...
- Arc GIS engine10.2与VS2012的安装及匹配步骤
本文章已收录于: .embody { padding: 10px 10px 10px; margin: 0 -20px; border-bottom: solid 1px #ededed } ...
- 关于ARC下需要dealloc的相关内容
今天在项目中使用KVO添加观察者模式的时候,在返回上一级的时候竟然崩了.可是,看了很久,代码没有问题.最后,终于知道了需要添加dealloc 防止以后再出错,所以,便纪录下来.关于ARC下需要手动释放 ...
- iOS 中 ARC 项目 兼容 MRC
iOS 项目中MRC 和 ARC 项目的代码兼容问题: 1.ARC 项目中导入 MRC 第三方类的时候要在此类上添加 -objc-arc. 2.MRC 项目中导入 ARC 类的时候要在次类上添加 -f ...
- ARC内存管理机制详解
ARC在OC里面个人感觉又是一个高大上的牛词,在前面Objective-C中的内存管理部分提到了ARC内存管理机制,ARC是Automatic Reference Counting---自动引用计数. ...
- objective-c 语法快速过(7)编译器特性ARC
ARC(是编译器特性) ARC是自iOS 5之后增加的新特性,完全消除了手动管理内存的烦琐,编译器会自动在适当的地方插入适当的retain.release.autorelease语句.你不再需要担心内 ...
- iOS通过ARC管理内存(内容根据iOS编程编写)
栈 当程序执行某个方法(或函数)时,会从内存中一个叫栈的区域分配一块内存空间,这块内存空间我们叫帧.帧负责保护程序在方法内声明的变量的值.在方法内声明的变量我们称之为局部变量. 当我们的程序开始启动, ...
随机推荐
- Android保存设置的PreferenceActivity
界面XML文件:preference_setting.xml <?xml version="1.0" encoding="UTF-8"?> < ...
- Migration of ASP.NET app from IIS6 to IIS7 (7.5)
For many of us familiar problem. You developing applications under IIS6 and you're about to move the ...
- ubuntu自定义服务模板
根据他人代码修改: #!/bin/sh ### BEGIN INIT INFO # Provides: <pragram name> # Required-Start: $local_fs ...
- 最近有机会接触到了angularJs
记点笔记 概念多了 理顺还待时日: 总的来说: 1.ng-src src属性 2.ng-href href属性 3.ng-checked 选中状态 4.ng-selected 被选择状态 5.ng- ...
- [XML] ResourceManager一个操作Resource的帮助类 (转载)
点击下载 ResourceManager.zip /// <summary> /// 类说明:Assistant /// 编 码 人:苏飞 /// 联系方式:361983679 /// 更 ...
- EnumWindows 使用
转载自csdn:http://blog.csdn.net/hairi/article/details/548064 EnumWindows 用来列举屏幕上所有顶层窗口. MSDN原话: The E ...
- SQLServer2008找出所有包含172.17.224.40字样的存储过程
SQLServer2008 找出所有包含172.17.224.40的存储过程 select distinct name from syscomments a,sysobjects b where ...
- jBPM 6 开发 eclipse 插件安装
jBPM 6 开发 eclipse 插件安装 概述 与之前的jBPM 5相比,jBPM 6 新引入的kjars及mavenized的特性,使流程开发设计与之前有了很大的不同,本文主要说明jBPM 6 ...
- C# 控制台程序 托盘图标 事件响应
static void Main(string[] args) { NotifyIconHelper ni = new NotifyIconHelper(); NotifyIconHelper.Sho ...
- 关于Java中的数组转变成字符串问题
1.用StringBuilder private static String arraytoString(int arr[]){ StringBuilder sb=new StringBuilder( ...