=== 代码规范 === 实例变量 hello.h文件 {{{ @interface Hello // 开放的实例变量;非基本数据类型需要添加引用标记,字符串(NSString)类型标记为copy,非字符串类型标记为retain或者strong。 @end }}} hello.m文件 {{{ @interface Hello (private) // 不开放的实例变量 @end @implementation Hello @synthesize example = _example // example作为初始化变量,而_example作为引用变量 - (void)viewDidLoad { // 初始化实例变量 Object *tmp = [[Object alloc] init]; self.example = tmp; [tmp release]; // 操作实例变量 [_example message]; } @end }}} === 视图控制器的生命周期方法编写规范 === {{{ - (void)dealloc { // 必须调用父类方法;使用引用变量来释放;释放完了以后必须将指针置空。 [super dealloc]; [_example release]; [_example = nil]; } - (void)loadView { // 必须调用父类方法;这里主要用于布局视图。 } - (void)viewDidLoad { // 初始化数据,比如发送网络请求。 } - (void)viewDidUnload { // 释放在loadView和viewDidLoad里初始化的实例变量,同时将指针置空。 // 因为图片浏览应用比较容易发生内存警告,所以比较好的做法是把图片实体释放掉; // 比如,通常cell包含imageView,在发生内存警告时,可以将imageView的image属性置空。 // 为了使释放的效率更高,可以将置空的代码放置在自动释放池的管理下,如下: NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; cell.imageView.image = nil; [pool release]; } - (void)viewWillAppear:(BOOL)animated { // } }}} === 构造网格视图 === 本应用所有网格都是规则的,因此可以使用3.0框架里的PCButtonCell视图,该视图允许开发者在上面添加若干个图片按钮,我们使用普通的列表就可以构造出一个网格视图。因为未必每个网格的样式都相同,比如说显示的文本、图标和位置不一样,所以基本PCButtonCell只包含一个PCButton。需要使用额外的视图构件比如UILabel或者UIImageView的,可以继承PCButtonCell然后自定义更加丰富的网格。假设每一行显示n个网格,下面是基本的使用方法: {{{ - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [dataSource count] / n + 1; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *identifier = @"BrowseLocalController"; PCButtonTableCell *cell = (PCButtonTableCell *)[tableView dequeueReusableCellWithIdentifier:identifier]; NSDictionary *cellConfig = [self.config objectForPath:PCUI_CONTENT_VIEW, PCUI_TABLE_VIEW, PCUI_TABLE_CELL, nil]; NSInteger countPreRow = n; // 网格的按钮都使用同一个回调方法,可以使用网格的tag来进行区分; if (!cell) { cell = [[PCButtonTableCell alloc] initWithConfig:cellConfig countPreRow:countPreRow target:self action:@selector(clickGrid:) style:UITableViewCellStyleDefault reuseIdentifier:identifier]; [cell autorelease]; } // 每次调用这个方法都必须配对调用showControllerFrom:和hideControlFrom:,因为单元格有重用机制,这样做可以保证单元格在重用以后可以显示正确的网格数。 // 如果需要自定义网格,这两个方法也必须被覆盖。子类必须调用父类实现,并实现额外的控制。 [cell showControlFrom:0]; for (NSInteger i=0; i=total_count时通知 - (void)save; // 将自己序列化到磁盘,路径为/home/Documents/save/classes/albumItems/,以albumId为标识符 - (void)deletePhoto:(Photo *)photo; // 删除某张图片,删除后需要重新序列化覆盖原来的项目 下载队列(DownloadQueue): @private + tasks : NSArray 元素为下载任务,下载完成之后将该元素序列化。 + (void)startTaskAtIndex:(NSInteger)idx; + (void)stopTaskAtIndex:(NSInteger)idx; + (void)deleteTaskAtIndex:(NSInteger)idx; + (void)receiveSuccesNotify:(NSNotification *)noti; + (BOOL)isLoading;//检查任务列表中是否还有loading状态的任务,但是因为队列中只有loading和waiting的任务,所以可以通过判断[tasks count]是否为0来实现。 + (void)notifyWhenDone; // 是所有任务都下载的时候通知,还是没有等待中任务也通知? + (void)addTask:(DownloadTask *)task; + (void)deleteTask:(DownloadTask *)task;// 用户主动删除任务 + (void)continueDownload;//从LocalItemManager中同步下载任务,在询问用户并得到用户的确认后执行该方法。 摄影师(Photographer) NSDictionary *properties; 关注的摄影师(FocusedPhotographer): @private + user_ids : NSArray 已关注的摄影师 + (void)getAllPhotographers; // 获取所有已经关注的摄影师 + (BOOL)haveFocusedPhotographer:(NSString *)user_id; // 判断是否已经关注了指定摄影师 + (void)focusPhotographer:(NSString *)user_id; // 关注某摄影师