iPhone企业应用实例分析之三:程序框架分析

iPhone企业应用实例分析之三:程序框架分析


WebDoc Mobile项目是典型的多层流程型系统,所以系统主要使用UINavigation Controller进行用户界面的导航,这样当用户从上一层界面进入下一层界面,在下一层界面的事情处理完以后,又可以方便地返回到上一层界面,在用户登录系统以后,系统显示主菜单,如图5-6所示。
主菜单分为4个选项,即“我的文档”、“部门文档”、“高级搜索”和“统计图”, 主菜单在MainViewController类中实现,该类使用UITableView来对菜单项进行管理, UITableView的数据源使用一个NSMutableArray来提供表格数据,表格绘制时,使用以下命令。
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection: (NSInteger)section{



return menuList.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath{
NSDictionary *dataDictionary = [menuList objectAtIndex:indexPath.row];
cell.textLabel.text = [dataDictionary valueForKey:kTitleKey];
return cell;
}
返回表格行数和每行的具体内容,每行表格数据包含下一层ViewController界面的标题和类名称,当用户单击主菜单的菜单项时,程序先使用该类名称调用NSClassFromString()创建类对象,然后再创建ViewController对象,并将ViewController加入UINavigation Controller中进行界面显示。
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath: (NSIndexPath *)indexPath{
targetViewController = [[NSClassFromString(viewControllerName) alloc] initWithNibName:viewControllerName bundle:nil];
[self.navigationController pushViewController:targetViewController animated:YES];
}
在用户选择“我的文档”或者选择“部门文档”界面的具体部门后,以及使用“文档搜索”功能搜索文档后,程序就显示文档列表,如图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];
}
}
因为DocumentDetailViewController类需要包含的内容较多,所以程序使用分页显示的方式来组织这些内容,DocumentDetailViewController类使用一个UISegmentedControl类来管理文档详情、文档附件、文档历史和工作流4个具体页面,如图5-8所示。
这样,当用户进入文档详情的时候,就可以方便地在文档附件、文档历史等页面之间进行切换,在DocumentDetailViewController类的viewDidLoad()方法中通过addTarget()函数设置UISegmentedControl页面切换时的响应函数,这个响应函数在UISegmentedControl对象创建时进行设置,这里设置的是didChangeSegmentControl函数。
self.segmentedControl = [[UISegmentedControl alloc] initWithItems:segmentTitles];
[self.segmentedControl addTarget:self
action:@selector(didChangeSegmentControl:)
forControlEvents:UIControlEventValueChanged];
当用户在页面之间切换时,这个函数就得到调用,函数首先将当前活动页面移除,然后再激活并显示用户选择的页面。



- (void)didChangeSegmentControl:(UISegmentedControl *)control {
if (self.activeViewController) {
[self.activeViewController viewWillDisappear:NO];
[self.activeViewController.view removeFromSuperview];
[self.activeViewController viewDidDisappear:NO];
}

self.activeViewController = [self.segmentedViewControllers objectAtIndex: control.selectedSegmentIndex];
[self.activeViewController viewWillAppear:YES];
[self.view addSubview:self.activeViewController.view];
[self.activeViewController viewDidAppear:NO];

}
这样就实现了在4个页面之间进行切换、隐藏和显示的功能。DocumentDetailView Controller类通过UISegmentedControl类来组织页面内容是程序的主体所在,也是编程的重点,该类通过另外4个类来组织和管理页面内容,另外4个类分别是DocDetailView Controller类,用来显示文档明细;DocFilesViewController类,用来管理文档附件;DocHistoryViewController类,用来管理文档变更历史;DocWorkflowViewController类,实现工作流管理。
当用户单击“部门文档”主菜单时,程序显示部门列表界面,如图5-9所示。
当用户选择具体部门时,程序通过Web Service查询服务器端的后台数据库,然后将服务器返回数据进行显示,即显示用户所选部门当前处理中的文档列表。
当用户选择“统计图”主菜单时,程序列出系统现有的统计图列表,如图5-10所示。
在用户单击统计图明细图标 时,程序通过Web Service查询服务器端后台数据库,并根据返回数据将统计图显示在手机上,如图5-11所示。




本文节选自《iOS软件开发揭密:iPhone&iPad企业应用和游戏开发》一书。
《iOS软件开发揭密:iPhone&iPad企业应用和游戏开发》一书已由电子工业出版社正式出版,本书由虞斌著。

购买地址:

当当网:
http://product.dangdang.com/product.aspx?product_id=21082051

卓越网:
http://www.amazon.cn/iOS%E8%BD%AF%E4%BB%B6%E5%BC%80%E5%8F%91%E6%8F%AD%E5%AF%86-iPhone-iPad%E4%BC%81%E4%B8%9A%E5%BA%94%E7%94%A8%E5%92%8C%E6%B8%B8%E6%88%8F%E5%BC%80%E5%8F%91-%E8%99%9E%E6%96%8C/dp/B0051HAIA4/ref=sr_1_1?s=books&ie=UTF8&qid=1306139777&sr=1-1

互动出版网:http://product.china-pub.com/198191

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值