图5-7 文档列表界面
文档列表显示使用DocListViewController类实现,该类包含文档记录分页,前后导航功能,当记录超过每页记录显示的最大行数时,用户可以使用前向和后向箭头进行翻页,另外在用户进行搜索以后,程序也使用这个类来显示搜索结果。
DocListViewController类包含一个UITableView成员变量,程序使用这个表格来显示文档列表,表格的数据源使用一个NSMutableArray来存储和提供数据,这个数组的每个元素都是一个DocumentDetailViewController类实例,在文档列表显示前使用一个遍历来创建这些DocumentDetailViewController类实例。
for(i = 0; i < nResult; i++){
DocumentDetailViewController *presidentsViewController =
[[NSClassFromString(viewControllerName) alloc]
initWithNibName:viewControllerName bundle:nil];
Document *doc = [objects objectAtIndex:i];
presidentsViewController.title = doc.documentName;
[presidentsViewController setDocument:doc];
[controllers addObject:presidentsViewController];
[presidentsViewController release];
}
当用户单击文档列表中的某个文档时,程序就从数组中取出对应的元素,然后显示DocumentDetailViewController对象。
- (void)tableView:(UITableView *)tableView
didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:YES];
NSUInteger row = [indexPath row];
if(self.controllers != nil){
DocumentDetailViewController *nextController = [self.controllers
objectAtIndex:row];
//preload detail, attachment and history.
[nextController preLoadData];
//clear cache
[self handleWithCache];
//push document detail view...
[self.navigationController pushViewController:nextController animated:YES];
}
}