展示收藏商户和浏览记录 城市信息 展示所选城市的生活信息如:医院、银行、公安机关等等 更多 显示自己的账户信息
第四章 详细设计与实现
根据需求分析,划分了九大功能模块,其中Neaby,List In Order,Coupons是本软件的特色及关键部分,具体功能如下所示:
4.1首页展示设计
下图4-1为首页界面,最上方用一个UIButton显示城市信息,程序运行时判断当前有无已选城市,第一次运行时判断无已选城市,会跳到城市选择界面(图4-2)。向下紧接着是一个UISearchBar,触碰此searchBar会进入搜索界面。下方显示红色图片的是UIScrollView,其上是九个UIButton,设置各button的背景图片即为所展现之场景,点击各个button会进入个相应界面。
图4-1 首页视图
以下代码为通过数据库判断是否已选择城市:
- (void)viewDidAppear:(BOOL)animated
{
MySqlite *mysql = [[MySqlite alloc] init];
if (flag > 0)
{
flag --;
}
if ([mysql getCity]==nil)
{
ChangeCity *city = [[ChangeCity alloc] init];
[self.navigationController pushViewController:city animated:YES];
[city release];
}
else
{
NSString *cityString = [NSString stringWithFormat:@"SPTK Dir. %@", [mysql getCity]];
UIButton *b = [UIButton buttonWithType:UIButtonTypeCustom];
b.tag = 13;
b.frame = CGRectMake(29, 6, 262, 33);
[b setTitle:cityString forState:UIControlStateNormal];
[b setImage:[UIImage imageNamed:@"head1"] forState:UIControlStateNormal];
[b setImageEdgeInsets:UIEdgeInsetsMake(0, 205, 0, 0)];
[b setTitleEdgeInsets:UIEdgeInsetsMake(0, -50, 0, 0)];
[b addTarget:self action:@selector(qwer:) forControlEvents:UIControlEventTouchUpInside];
b.titleLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:18];
self.navigationItem.titleView = b;
}
[mysql release];
}
4.2附近模块设计
如下图4-2为附近界面,用一个UITableView列表显示信息。
在viewController中设置此tableView的delegate和dataSource为self。在viewController声明文件中遵循UITableViewDelegate和UITableViewDataSource协议,在实现文件中实现UITableViewDelegate和UITableViewDataSource的相应方法:主- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section,- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath。
图4-2附近界面
代码如下:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [[ListData objectAtIndex:0] count];
}
上面的方法中return的数据为一个section的行数。
- (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.textLabel.text = [[ListData objectAtIndex:0] objectAtIndex:indexPath.row];
cell.textLabel.font = [UIFont boldSystemFontOfSize:14];
cell.imageView.image = [UIImage imageNamed:[[ListData objectAtIndex:1] objectAtIndex:indexPath.row]];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
return cell;
}
上面的方法中是实现cell的具体代码。
点击各cell时,调用- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;方法,进入相应界面代码如下:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.row == 0)
{
SearchCoupon *tabView = [[SearchCoupon alloc] init];
TKSPAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
[appDelegate.navigationController pushViewController:tabView animated:YES];
[tabView release];
}
else if ([[[ListData objectAtIndex:0] objectAtIndex:indexPath.row] isEqualToString:@"More classification"])
{
MoreCategoriesTable *nextView = [[MoreCategoriesTable alloc] init];
nextView.title = @"More classification";
[self.navigationController pushViewController:nextView animated:YES];
[nextView release];
}
else
{
NearbyOther *nextView = [[NearbyOther alloc] init];
nextView.flag = 0;
nextView.lat = lats;
nextView.lon = lons;
nextView.string = [[ListData objectAtIndex:0] objectAtIndex:indexPath.row];
nextView.title = [[ListData objectAtIndex:0] objectAtIndex:indexPath.row];
[self.navigationController pushViewController:nextView animated:YES];
[nextView release];
}
}
4.3搜索模块设计
如图4-3为搜索界面:
图4-3搜索界面
在表格的上方是一个searchBar,设置此表格的headerView为此searchBar,可以实现此searchBar随着table上下拖动。触碰上方的searchBar后触发- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText;方法,代码如下:
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
{
if ([NearbyLogicControl connectedToNetwork])
{
NearbyLogicControl *logic = [[NearbyLogicControl alloc] init];
searchData.listData = [logic getSearchDetail:searchText];
[logic release];
self.searchDisplayController.searchResultsDataSource = searchData;
self.searchDisplayController.searchResultsDelegate = searchData;
}
}
上述代码中:首先判断是否连接网络:[NearbyLogicControl connectedToNetwork],若值为yes,则根据输入的字符串进行搜索并显示。显示时,要设置searchDisplayController的searchResultsDataSource和searchResultsDelegate的值为searchData。
搜索结果如图4-4显示:
图4-4搜索结果界面
4.4签到模块设计
如图4-5为签到界面:
由于页面较多采用UITabBarController, 将各个viewController添加到一个数组,再设置UITabBarController的viewControllers为此数组即可。当需要组织或组合多个不同领域的功能时,就可以使用UITabBarController。每个功能领域有自己的图标按钮,并且只有用户单击它时才激活。通过setTitle设置每个功能图标的名称,setImage设置图片。
图4-5签到界面
实现代码如下:
- (id)init
{
self = [super initWithNibName:nil bundle:nil];
if (self)
{
self.title = @"Check-in";
Activity * SecondTabView = [[Activity alloc] init];
[SecondTabView.tabBarItem setTitle:@"Activities"];
[SecondTabView.tabBarItem setImage:[UIImage imageNamed:@"a2"]];
UIViewController *ThirdTabView;
MySqlite *mysql = [[MySqlite alloc] init]
上一篇:
基于IOS的在线音乐播放系统的开发本科生毕业论文
下一篇:
记录文件6:基于IOS的易车新闻客户端