1,业务介绍
这是一款贴近大众生活的移动应用,为了更方便大众生活而设计的一款APP。
2,架构介绍
这个客户端总体分了4个模块,每个模块都是采用了MVC的架构模式来分离视图与数据的解耦合。Model层我们抽离出了一个BaseModel基类,将JSON数据填充到Model对象的逻辑封装到这个基类中;控制器层,我们抽取出了BaseViewController,将共性的方法与属性定义在这个基类中,例如加载提示、返回按钮、数据请求对象等等;View视图层,需要大量子类化视图控件都抽取出基类,方便以后的扩展与维护,例如:BaseView、BaseCell, BaseTableView中我们封装了上拉下拉功能,这样大量上拉下拉的表视图继承这个类就可以了。整体UI界面的创建采用了Storyboard。
3,技术点介绍
(1)网络请求,我们使用了开源框架MKNetworkKit,以及SBJson进行数据解析;
(2)界面上,我们使用了tableView及scrollView显示加载的数据,同时我们使用了xib及storyboard对图片和文字进行排版,使画面更加清晰好看;
(3)类与类的通信,适当的使用了block进行数据的传输;
(4)接入大众点评的SDK,访问大众点评的开放平台的网络接口;
4,总结
熟练运用tableView显示数据,以及各种xib和storyboard的加载,各种开源框架的运用,将会使我们在书写代码时,更轻易的完善代码,流畅的体现我们的思想。同时,其他各种view的穿插使用,将会使我们的app更具美感。当然,排版也是我们需要注意的问题。
5,主要代码及运行结果
- (void)_createMainVC{
NSArray *nameArray = @[@"Home",@"Group",@"Find",@"Profile"];
NSMutableArray *array = [NSMutableArrayarray];
for (int i =0; i < 4; i ++) {
NSString *name = nameArray[i];
UIStoryboard *storyboard = [UIStoryboardstoryboardWithName:name bundle:nil];
UINavigationController *vc = [storyboardinstantiateInitialViewController];
[array addObject:vc];
}
self.viewControllers = array;
}
- (void)_createTabbarView{
Class clas = NSClassFromString(@"UITabBarButton");
for (UIView *viewin self.tabBar.subviews) {
if ([view isKindOfClass:clas]) {
[view removeFromSuperview];
}
}
_tabbarView = [[UIViewalloc] init];
_tabbarView.frame =CGRectMake(0,0,kScreenWidth, 49);
[self.tabBaraddSubview:_tabbarView];
_tabbarView.userInteractionEnabled =YES;
NSArray *normalImages =@[@"home_footbar_icon_dianping@2x.png",
@"home_footbar_icon_group@2x.png",
@"home_footbar_icon_search@2x.png",
@"home_footbar_icon_my@2x.png"
];
NSArray *highImages = @[
@"home_footbar_icon_dianping_pressed@2x.png",
@"home_footbar_icon_group_pressed@2x.png",
@"home_footbar_icon_search_pressed@2x.png",
@"home_footbar_icon_my_pressed@2x.png"
];
NSArray *titles = @[@"首页",
@"团购",
@"发现",
@"我的"
];
CGFloat kwidth = kScreenWidth/4.0;
for (int i =0; i < 4; i ++) {
UIButton *button = [UIButtonbuttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(kwidth * i, 2, kwidth, 45);
button.imageEdgeInsets = UIEdgeInsetsMake(5, 27.5, 20, 27.5);
[button setFont:[UIFontsystemFontOfSize:14.0f]];
[button setImage:[UIImageimageNamed:normalImages[i]] forState:UIControlStateNormal];
[button setImage:[UIImageimageNamed:highImages[i]] forState:UIControlStateSelected];
button.titleEdgeInsets = UIEdgeInsetsMake(25, -50,0, 0);
[button setTitle:titles[i]forState:UIControlStateNormal];
[button setShowsTouchWhenHighlighted:YES];
[button setTitleColor:[UIColorgrayColor] forState:UIControlStateNormal];
[button setTitleColor:kNaviColorforState:UIControlStateSelected];
button.tag = 100 + i;
if (i == 0) {
[button setSelected:YES];
}
[button addTarget:selfaction:@selector(selectButton:)forControlEvents:UIControlEventAllEvents];
[_tabbarView addSubview:button];
}
}
- (void)selectButton:(UIButton *)button{
for (int i =0; i < 4; i ++) {
UIButton *but = (UIButton *)[_tabbarViewviewWithTag:100 + i];
if ((button.tag -100 )!= i) {
[but setSelected:NO];
}else{
[but setSelected:YES];
}
}
[self setSelectedIndex:button.tag -100];
}