《我的佛典》截图赏析
我看到这些是非常欢喜阿,自己的软件不算什么,至少大家可以更方便的看佛经了!
IPhone, Cocoa, PHP, Javascript, JQuery, Actionscript, etc…
Archive for 八月 2009
我看到这些是非常欢喜阿,自己的软件不算什么,至少大家可以更方便的看佛经了!

Three20库是再好不过的iPhone开发资源了,尤其是其中提供的TT图片视图控制器提供了简单易用的图片浏览功能,下面我就简单的介绍了一下如何使用TTPhotoViewController
/*********************************************************************************************/首先我们建立一个TTPhotoViewController的子类:
@interface LibDetailViewController : TTPhotoViewController {
然后在viewDidLoad代理方法中添加数据源(datasource)
... ... for (NSInteger i=1; i<=libLength; i++) { picIndex = [Zeros stringByAppendingString:[NSString stringWithFormat:@"%d",i]]; picIndex = [picIndex substringFromIndex:([picIndex length] - libDigits)]; [photosArray addObject:[[[MockPhoto alloc] initWithURL:[NSString stringWithFormat:@"%@%@/o/%@%@%@.jpg",addr,libName,libName,addiPage,picIndex] smallURL:[NSString stringWithFormat:@"%@%@/%@%@%@.jpg",addr,libName,libName,addiPage,picIndex] size:CGSizeMake(320, 480)]autorelease]]; //这一行是最重要了,因为TTPhotoViewController需要的是一个TTPhotoSource作为数据源对象, //但是这个对象其实就是一个TTPhoto的数组,所以我们在这里创建并添加所有的图片信息到一个可变数组内。 } self.photoSource = [[[MockPhotoSource alloc] initWithType:MockPhotoSourceDelayed title:libTitle photos:photosArray photos2:nil] autorelease]; //这里初始化并赋值这个TTPhotoSource对象到self.photoSource上 [photosArray release]; //由于self会retainphtosArray,所以可以release掉它了。
我在这里使用了Three20样例sample里面的类MockPhotoSource来创建TTPhoto和TTPhotoSource对象。
就这么简单,你就可以使用TTPhotoViewCotroller的便利咯~
JSON我就不多解释了,需要更多信息的朋友请到json.org上查看。
在iPhone上访问网络内容是很必须的,而一些数据就需要以某种形式储存在web服务器上。比如一个app的目录,内容,索引等等。而xml和json,plist都是比较方便的方式。
-XML在iPhone上是非常好用的,但是对复杂的数据结构使用上就不那么方便了,具体可以参阅苹果的“基于事件的XML”和“基于树的XML”编程向导
-plist是再方便不过了,不过我看最多也就是一个NSDictionary而已,复杂一些的话,数据输入上也会非常非常的麻烦。
-JSON本来是不被苹果支持的,但是有人很Nice的帮我们解决了这个问题:JSON for OBJC http://code.google.com/p/json-framework/
基本上来说,这个框架异常的简单易用,会将得到的json字符串处理成一个复杂NSDictionary对象,而每一个值都还是一个NSDictionary对象
比如:
{
"华藏净宗学会":
{
"zhaomu":
{
"name":"净宗朝暮课本",
"length":142,
"digits":3
},
"kesong":
{
"name":"净宗共修课本",
"length":75,
"digits":2
}
},
"生命基金会":
{
"dabei88":
{
"name":"大悲出相图",
"length":88,
"digits":2
}
}
}就会转换为一个复杂无比的NSDictionary:
[[NSDictionary alloc] initWithObjects:[NSArray arrayWithObjects: [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects: [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects: @"净宗朝暮课本", @"142", @"3",nil] forKeys: [NSArray arrayWithObjects: @"name", @"length", @"digits",nil]], [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects: @"净宗共修课本", @"75", @"2",nil] forKeys: [NSArray arrayWithObjects: @"name", @"length", @"digits",nil]],nil] forKeys:[NSArray arrayWithObjects:@"zhaomu",@"kesong",nil]], [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects: [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects: @"大悲出相图", @"88", @"2",nil] forKeys: [NSArray arrayWithObjects: @"name", @"length", @"digits",nil]],nil] forKeys:[NSArray arrayWithObjects:@"dabei88",nil]],nil] forKeys:[NSArray arrayWithObjects:@"华藏净宗学会",@"生命基金会",nil]];
我是非常佩服自己能打出来上面的巨大无比的定义式。。。。没有编译错误
不管怎么样,转换后,在系统中就可以非常方便的使用json的键值结构信息咯~!!!
UITableViewController 列表在iPhone开发中起着决定性的重要作用,但是UITableViewController并不是那么简单使用的,以下就是其中的重要方法和Delegate:
//这个delegate会获取有多少个"章节" - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; //这里返回的是章节(section)的个数 //如果数据源是一个复杂array或dictionary,则可以返回 return [NSArray count]; 作为章节的个数 } //这个delegate会获取章节内有多少行 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return 0; //这个部分是必须要改的,否则0行的话,就是一个空表了 //如果数据源是一个复杂array或dictionary, 可以使用嵌套的查询来返回这个个数了 //比如: return [[NSArray objectAtIndex:section] //section为整数,所以如果使用NSDictionary, //记得使用辅助方法来计算其索引的key,或嵌套查询 count]; //因为返回的依旧是一个array或dictionary对象,所以我们获取它的大小count } // 这里编辑每个栏格的外观 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; } // 一般我们就可以在这开始设置这个cell了,比如设置文字等: cell.textField.text = [NSArray objectAtIndex:indexPath.row]; //假设这个NSArray就是本section的数据了,否则需要嵌套来查询section的信息,如前一个delegate return cell; } //当栏格被点击后需要触发的事件 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { AnotherViewController *anotherViewController = [[AnotherViewController alloc] initWithNibName:@"AnotherView" bundle:nil]; // 建立并使用本地导航管理推入视图控制器是最普遍的方法 [self.navigationController pushViewController:anotherViewController]; [anotherViewController release]; } // 该delegate是可选的,对那些可以被编辑的对象返回YES - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { // Return NO if you do not want the specified item to be editable. return YES; } // 对特定编辑风格进行操作 - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { //以下是apple的缺省实例 if (editingStyle == UITableViewCellEditingStyleDelete) { // 如果是要删除那行栏格,那么就去删除数据源中的对象 [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES]; } else if (editingStyle == UITableViewCellEditingStyleInsert) { // 如果是要添加栏格,那么就应该将要添加的内容添加到数据源中 } } // 可选delegate,对那些被移动栏格作特定操作 - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath { } // 对那些可以移动的行返回YES - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath { // 如果不像让栏格移动,就返回NO return YES; }
以上就是所有重要的delegate方法,只要数量使用这些方法,我们就能创建和自定义自己想要的iPhone表格
V 在Mac上可以简单的使用一个内建API进行文字读取朗读。很可惜不支持中文…
@interface AppController : NSObject { NSSpeechSynthesizer *speechSyn; //创建语音合成器对象 } //初始化对象 speechSyn = [[NSSpeechSynthesizer alloc] initWithVoice:nil]; //然后就可以直接让这个合成器读取任何NSString了,是不是太简单了? [speechSyn startSpeakingString:@"This is what I gonna read"];
最后,别忘了release掉它阿~