2013年5月2日
摘要: schedule是CCNode的成员函数,作用是任务调度。即每隔一段时间调用一次方法。在很多情况下,你需要节点调用指定的更新方法以处理某些情况,比如碰撞检测。一、scheduleUpdate 1 - (id)init { 2 if (self=[super init]) { 3 [self scheduleUpdate]; //此方法会每一帧调用一次update:方法 4 } 5 } 6 7 // 重载CCNode的update:方法 8 // delta参数表示此方法的最后一次调用到现在所经过的时间 9 - (void)update:(ccTime)delt... 阅读全文
posted @ 2013-05-02 16:27 蓝易 阅读(536) 评论(0) 推荐(0) 编辑
  2013年4月30日
摘要: 一、NSMutableDictionary的使用 阅读全文
posted @ 2013-04-30 04:21 蓝易 阅读(144) 评论(0) 推荐(0) 编辑
摘要: 一、NSDictionary的使用 1 int main(int argc, const char * argv[]) 2 { 3 4 @autoreleasepool { 5 6 // 创建方式一 7 NSDictionary *dict1 = [NSDictionary dictionaryWithObjectsAndKeys: 8 @"value1", @"key1", 9 @"value2", @"key... 阅读全文
posted @ 2013-04-30 04:18 蓝易 阅读(156) 评论(0) 推荐(0) 编辑
摘要: 一、NSMutableArray的使用 1 int main(int argc, const char * argv[]) 2 { 3 4 @autoreleasepool { 5 6 NSMutableArray *arr1 = [NSMutableArray arrayWithObjects:@"1", @"2", nil]; 7 // 添加元素,该元素引用计数器加1 8 [arr1 addObject:@"3"]; 9 // 删除指定元素,该元素引用计数器减110 [arr1 re... 阅读全文
posted @ 2013-04-30 03:26 蓝易 阅读(128) 评论(0) 推荐(0) 编辑
摘要: 一、NSArray的使用 1 int main(int argc, const char * argv[]) 2 { 3 4 @autoreleasepool { 5 6 // 创建有多个元素的数组,nil代表数组元素结束 7 NSMutableString *s1 = [NSMutableString stringWithString:@"a"]; 8 NSMutableString *s2 = [NSMutableString stringWithString:@"b"]; 9 N... 阅读全文
posted @ 2013-04-30 03:07 蓝易 阅读(179) 评论(0) 推荐(0) 编辑
摘要: 一、NSMutableString的使用 1 int main(int argc, const char * argv[]) 2 { 3 4 @autoreleasepool { 5 6 // 预先分配10个字数的存储空间 7 NSMutableString *s1 = [NSMutableString stringWithCapacity:10]; 8 // 设置字符串内容 9 [s1 setString:@"1234"];10 // 追加字符串11 [s1 appen... 阅读全文
posted @ 2013-04-30 01:09 蓝易 阅读(124) 评论(0) 推荐(0) 编辑
  2013年4月29日
摘要: 一、NSString的创建 1 int main(int argc, const char * argv[]) 2 { 3 4 @autoreleasepool { 5 6 //这种方式不需要release 7 NSString *s1 = @"this is a string"; 8 NSLog(@"s1=%@", s1); 9 10 //这种方式需要release11 NSString *s2 = [[NSString alloc] init];12 ... 阅读全文
posted @ 2013-04-29 22:13 蓝易 阅读(147) 评论(0) 推荐(0) 编辑
  2013年4月28日
摘要: Block语法:1 int (^sum)(int, int) = ^(int a, int b) {2 return a+b;3 };以上代码定义了一个名为sum的Block对象,它带有两个int参数,返回int,等式右边就是Block的具体实现。调用方法:1 int i = sum(10, 20);2 NSLog(@"%i", i);使用typedef定义Block: 1 typedef int (^Sum) (int, int); 2 3 int main(int argc, const char * argv[]) 4 { 5 6 @autoreleasepool { 阅读全文
posted @ 2013-04-28 16:36 蓝易 阅读(204) 评论(0) 推荐(0) 编辑
摘要: Protocol简单来说就是一系列不属于任何类的方法列表,其中声明的方法可以被任何类实现,这种模式一般称为代理模式(delegation)。通过Protocol定义各种行为,在不同的场景采用不同的实现方式。在Xcode上新建文件,选择Objective-C protocol方式创建Protocol:Protocol填写协议名:因为Protocol可以被任何类实现,所以只会生成一个头文件:ButtonDelegate.h 1 #import <Foundation/Foundation.h> 2 3 @class Button; 4 5 // Protocol本身可以继承 6 @pr 阅读全文
posted @ 2013-04-28 16:35 蓝易 阅读(509) 评论(0) 推荐(0) 编辑
摘要: 一、Category的使用无论一个类设计的如何完美,都不可避免的会遇到没有预测到的需求,那怎么扩展现有的类呢?当然,继承是个不错的选择。但是Objective-C提供了一种特别的方式来扩展类,称为Category,可以动态的为现有的类添加新的行为。例如,我们现在有一个Person类。Person.h1 @interface Person : NSObject2 3 - (void) test;4 5 @endPerson.m1 #import "Person.h"2 3 @implementation Person4 5 - (void)test {6 NSLog(@&qu 阅读全文
posted @ 2013-04-28 16:34 蓝易 阅读(378) 评论(0) 推荐(0) 编辑