05 2011 档案

摘要:要求显示某个时间的格式如下:12:34昨天 12:34前天 20:10本周一 21:15上周二 10:213月21日 21:142010年10月21日 19:32通过JS输出可编码如下:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">& 阅读全文
posted @ 2011-05-27 21:14 chenjunbiao 阅读(413) 评论(0) 推荐(0)
摘要:现有AMR的语音音频n段,要求在HTML5浏览器上播放,并且是在输出流时即进行拼接,不需在浏览器用脚本进行分段播放。根据 AMR文件格式分析 可知,拼接时需要将从第2段开始的amr字节流中去掉前6个字节"#!AMR "。以下两个例子分别是指定Content-Length和使用chunked方式输出,其中chunked方式在移动设备浏览器中不可用。chunked输出方式: public class AudioHandler : IHttpHandler { public void ProcessRequest(HttpContext context) { //参数验证 str 阅读全文
posted @ 2011-05-13 18:51 chenjunbiao 阅读(1025) 评论(1) 推荐(0)
摘要:通过分类的方式可以为已存在的类添加新的方法,甚至不需要源码,有点像C#中的扩展方法。这时提供一个例子是把一个字符串转换为驼峰式并且出掉单词空格。NSString+CamelCase.h#import <Foundation/Foundation.h>//NSString 表示将要添加分类的类名称,该类必须是已存在的。//CamelCase 是为类添加的分类的名称。//只能添加方法,不能添加变量。//头文件命名惯例:ClassName+CategoryName.h@interface NSString (CamelCase)-(NSString*) camelCaseString;@ 阅读全文
posted @ 2011-05-12 10:17 chenjunbiao 阅读(1167) 评论(0) 推荐(0)
摘要:实现了NSFastEnumeration协议的集合的都可以使用快速枚举的特性,如NSArray, NSDictionary, NSSet, NSEnumerator等。注意这里NSEnumerator也实现了NSFastEnumeration协议,这样可以执行一些特殊的任务,如使用reverseObjectEnumerator来对数组进行反同查询。快速枚举的格式如下:for(type loopVariable in expression){ 语句}下面的例子关注一下不同退出循环的方式,loopVariable值的变化:#import <Foundation/Foundation.h> 阅读全文
posted @ 2011-05-11 10:20 chenjunbiao 阅读(903) 评论(0) 推荐(0)
摘要:集合类(如:NSArray、NSSet、NSDictionary等)均可获取到NSEnumerator, 该类是一个抽象类,没有用来创建实例的公有接口。NSEnumerator的nextObject方法可以遍历每个集合元素,结束返回nil,通过与while结合使用可遍历集合中所有项。例子中使用了与前例相同的Photo对象,具体定义参考隐式循环这一节。#import <Foundation/Foundation.h>#import "Photo.h"int main (int argc, const char * argv[]){ NSAutoreleasePoo 阅读全文
posted @ 2011-05-11 09:40 chenjunbiao 阅读(3564) 评论(1) 推荐(1)
摘要:定义一个Photo类,并带有2个draw方法, 一个带参数、一个不带参数。Photo.h#import <Foundation/Foundation.h>@interface Photo : NSObject {@private }-(void) draw;-(void) draw:(NSNumber*) number;@endPhoto.m#import "Photo.h"@implementation Photo- (id)init{ self = [super init]; if (self) { // Initialization code here. 阅读全文
posted @ 2011-05-10 10:37 chenjunbiao 阅读(910) 评论(0) 推荐(0)
摘要:代码:#import <Foundation/Foundation.h>int main (int argc, const char * argv[]){ NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; //Objective-C 没有提供相关的函数生成随机数,不过C供了rand(), srand(), random(), srandom(), arc4random()几个函数。 //其中arc4random()不用seed //生成0到100的随机数 int x = arc4random() % 100; 阅读全文
posted @ 2011-05-10 09:58 chenjunbiao 阅读(630) 评论(0) 推荐(0)
摘要:1. 服务器端返回json时,日期对象经常是/Date(1304902921487)/ 这种格式。使用如下代码转换成js正常的Date对象。value = new Date(parseInt(value.replace("/Date(", "").replace(")/",""), 10));2. 另一种方式是使用Epoch格式时间,即1970年1月1日到目前的毫秒数。这种处理方式可以进行更好的转换。 阅读全文
posted @ 2011-05-09 17:44 chenjunbiao 阅读(208) 评论(0) 推荐(0)
摘要:参考文章:http://blog.codingmylife.com/?p=85#import <Foundation/Foundation.h>int main (int argc, const char * argv[]){ NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; NSString *path = @"/Users/billchen/Desktop/f1.rtf"; NSString *temp = @"Hello Friend"; int i = 100; 阅读全文
posted @ 2011-05-09 13:14 chenjunbiao 阅读(2681) 评论(0) 推荐(0)
摘要:NSNumber可以包装常规的C类型成为一个Objective-C对象,可以存储任何的数字类型,以及BOOL和char。#import <Foundation/Foundation.h>int main (int argc, const char * argv[]){ NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; NSMutableArray *array = [NSMutableArray arrayWithCapacity:3]; [array addObject:[NSNumber numberWit 阅读全文
posted @ 2011-05-06 10:10 chenjunbiao 阅读(2530) 评论(0) 推荐(0)
摘要:NSMutableSet 集合成员是无序的。对对象进行枚举所得到对象的顺序不能保证相同。向集合中添加相同对象时只会保留一个副本。和其它集合类一样添加移除对象都会分别收到retain和release消息。#import <Foundation/Foundation.h>int main (int argc, const char * argv[]){ NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; NSMutableSet *fruits = [NSMutableSet setWithCapacity:2]; 阅读全文
posted @ 2011-05-06 10:02 chenjunbiao 阅读(736) 评论(0) 推荐(0)
摘要:NSMutableDictionary 用于处理值对集合。保存到键的对象必须实现了copyWithZone:方法。和NSMutableArray一样添加到容器时对象收到retain消息,把对象从容器中移除时收到release消息,任何想在移除对象还要对该对象进行操作必须先对该对象发出一条retain消息,在使用完成后需要release。#import <Foundation/Foundation.h>int main (int argc, const char * argv[]){ NSAutoreleasePool * pool = [[NSAutoreleasePool all 阅读全文
posted @ 2011-05-06 09:53 chenjunbiao 阅读(3280) 评论(1) 推荐(0)
摘要:NSMutableArray 只能保存Objective-C对象,没有边界检查,超出边界会抛出运行时异常。添加到Array中的对象会收到一条retain消息,当从数组中删除该对象或者数组本身被release了数组中的对象都会收到一条release消息。#import <Foundation/Foundation.h>int main (int argc, const char * argv[]){ NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; NSMutableArray *mutableFruitBask 阅读全文
posted @ 2011-05-06 09:32 chenjunbiao 阅读(592) 评论(0) 推荐(0)
摘要:1. 折分字符串操作:#import <Foundation/Foundation.h>int main (int argc, const char * argv[]){ NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; //将一个句子分解为单独的单词 NSString *string1 = @"my name is bill"; NSArray *words = [string1 componentsSeparatedByCharactersInSet:[NSCharacterSet wh 阅读全文
posted @ 2011-05-04 10:12 chenjunbiao 阅读(817) 评论(0) 推荐(0)
摘要:在Objective-C中是没有静态类变量一说的,不过我们可以模拟出来,但如果类对象之间还有继承关系,这样就一点复杂的了。我们这里假设一个Coupon类对象需要保存当前还剩多少有优惠券,还有一个继承于Coupon类对象的NewCoupon类对象,但它也保存有自已可用的优惠券的数量,我们如何保证他们的静态类变量相互独立,请看下面的例子。Coupon.h#import <Foundation/Foundation.h>@interface Coupon : NSObject { }+(int) numberCouponsLeft;+(void) resetCoupon;@endCoup 阅读全文
posted @ 2011-05-03 10:24 chenjunbiao 阅读(982) 评论(0) 推荐(0)