Skip to content

Commit

Permalink
新增cell
Browse files Browse the repository at this point in the history
  • Loading branch information
lookingstars committed Sep 25, 2015
1 parent 82a32da commit c669d28
Show file tree
Hide file tree
Showing 7 changed files with 179 additions and 9 deletions.
10 changes: 10 additions & 0 deletions nuomi.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
/* Begin PBXBuildFile section */
D174033C6D68CEB91E1537D3 /* libPods.a in Frameworks */ = {isa = PBXBuildFile; fileRef = D9C8EEB1E4AAC86ED2612F16 /* libPods.a */; };
E3A3FB051BB4DF88000E9729 /* JZHomepageModel.m in Sources */ = {isa = PBXBuildFile; fileRef = E3A3FB041BB4DF88000E9729 /* JZHomepageModel.m */; };
E3A3FB0B1BB52BCF000E9729 /* HomeMenuCell.m in Sources */ = {isa = PBXBuildFile; fileRef = E3A3FB0A1BB52BCF000E9729 /* HomeMenuCell.m */; };
E3A3FB0D1BB536E8000E9729 /* icon_homepage_entertainmentCategory@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = E3A3FB0C1BB536E8000E9729 /* icon_homepage_entertainmentCategory@2x.png */; };
E3B7F05D1BB23600001F4E16 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = E3B7F05C1BB23600001F4E16 /* main.m */; };
E3B7F0601BB23600001F4E16 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = E3B7F05F1BB23600001F4E16 /* AppDelegate.m */; };
E3B7F0631BB23600001F4E16 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = E3B7F0621BB23600001F4E16 /* ViewController.m */; };
Expand Down Expand Up @@ -229,6 +231,9 @@
D9C8EEB1E4AAC86ED2612F16 /* libPods.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libPods.a; sourceTree = BUILT_PRODUCTS_DIR; };
E3A3FB031BB4DF88000E9729 /* JZHomepageModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JZHomepageModel.h; sourceTree = "<group>"; };
E3A3FB041BB4DF88000E9729 /* JZHomepageModel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JZHomepageModel.m; sourceTree = "<group>"; };
E3A3FB091BB52BCF000E9729 /* HomeMenuCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HomeMenuCell.h; sourceTree = "<group>"; };
E3A3FB0A1BB52BCF000E9729 /* HomeMenuCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HomeMenuCell.m; sourceTree = "<group>"; };
E3A3FB0C1BB536E8000E9729 /* icon_homepage_entertainmentCategory@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "icon_homepage_entertainmentCategory@2x.png"; sourceTree = "<group>"; };
E3B7F0571BB23600001F4E16 /* nuomi.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = nuomi.app; sourceTree = BUILT_PRODUCTS_DIR; };
E3B7F05B1BB23600001F4E16 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
E3B7F05C1BB23600001F4E16 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -995,6 +1000,7 @@
E3B7F2211BB3A35F001F4E16 /* 首页 */ = {
isa = PBXGroup;
children = (
E3A3FB0C1BB536E8000E9729 /* icon_homepage_entertainmentCategory@2x.png */,
E3B7F2221BB3A35F001F4E16 /* icon_nav_cart_normal@2x.png */,
E3B7F2231BB3A360001F4E16 /* icon_nav_cart_normal@3x.png */,
E3B7F2241BB3A360001F4E16 /* icon_nav_cart_pressed@2x.png */,
Expand Down Expand Up @@ -1069,6 +1075,8 @@
E3B7F23D1BB3CDDE001F4E16 /* 首页 */ = {
isa = PBXGroup;
children = (
E3A3FB091BB52BCF000E9729 /* HomeMenuCell.h */,
E3A3FB0A1BB52BCF000E9729 /* HomeMenuCell.m */,
E3B7F23F1BB3CE8C001F4E16 /* JZHomeShopCell.h */,
E3B7F2401BB3CE8C001F4E16 /* JZHomeShopCell.m */,
E3B7F2421BB3CEC9001F4E16 /* JZHomeNewCell.h */,
Expand Down Expand Up @@ -1282,6 +1290,7 @@
E3B7F2161BB3960F001F4E16 /* sapi-nav-back-btn-bg.png in Resources */,
E3B7F2171BB3960F001F4E16 /* textfieldDelete@2x.png in Resources */,
E3B7F1F91BB3960F001F4E16 /* icon_nav_quxiao_normal@3x.png in Resources */,
E3A3FB0D1BB536E8000E9729 /* icon_homepage_entertainmentCategory@2x.png in Resources */,
E3B7F1CC1BB3960F001F4E16 /* gsafe@3x.png in Resources */,
E3B7F1371BB393C6001F4E16 /* icon_refresh_3@2x.png in Resources */,
E3B7F1DB1BB3960F001F4E16 /* ic_order_insurance@3x.png in Resources */,
Expand Down Expand Up @@ -1445,6 +1454,7 @@
E3B7F0631BB23600001F4E16 /* ViewController.m in Sources */,
E3A3FB051BB4DF88000E9729 /* JZHomepageModel.m in Sources */,
E3B7F2471BB3DC04001F4E16 /* JZHomeJingxuanCell.m in Sources */,
E3A3FB0B1BB52BCF000E9729 /* HomeMenuCell.m in Sources */,
E3B7F2441BB3CEC9001F4E16 /* JZHomeNewCell.m in Sources */,
E3B7F0E71BB2A8AF001F4E16 /* JZBaseTabBarViewController.m in Sources */,
E3B7F2501BB3E90F001F4E16 /* OPDataResponse.m in Sources */,
Expand Down
Binary file not shown.
15 changes: 7 additions & 8 deletions nuomi/Controller/首页/JZHomeViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#import "JZNetworkSingleton.h"
#import "JZHomeShopModel.h"
#import "JZHomepageModel.h"
#import "HomeMenuCell.h"

@interface JZHomeViewController ()<UITableViewDataSource, UITableViewDelegate>

Expand Down Expand Up @@ -100,8 +101,8 @@ -(void)getHotData {
_topenModel = _homepageM.topten;

// [weakself.tableView reloadData];
NSLog(@"special===: %@",_homepageM.special);
NSLog(@"topten===: %@",_homepageM.topten);
// NSLog(@"special===: %@",_homepageM.special);
// NSLog(@"topten===: %@",_homepageM.topten);
} failure:^(NSError *error) {
NSLog(@"获取 首页 数据失败");
}];
Expand Down Expand Up @@ -164,14 +165,12 @@ -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPat

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row == 0) {
static NSString *cellIndentifier = @"cell0";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIndentifier];
static NSString *cellIndentifier = @"menucell";
HomeMenuCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIndentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIndentifier];
cell = [[HomeMenuCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIndentifier menuArray:_categoryArray];
}

cell.textLabel.text = @"美食,电影";
//赋值
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}else if(indexPath.row == 1){
static NSString *cellIndentifier = @"JZHomeJingxuanCell";
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion nuomi/Utility/MenuButton/JZMenuButton.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ @implementation JZMenuButton
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
self.imageView.contentMode = UIViewContentModeScaleAspectFit;
self.imageView.contentMode = UIViewContentModeCenter;
self.titleLabel.textAlignment = NSTextAlignmentCenter;
self.titleLabel.font = [UIFont systemFontOfSize:12];
self.titleLabel.textColor = [UIColor blackColor];
Expand Down
17 changes: 17 additions & 0 deletions nuomi/Views/首页/首页/HomeMenuCell.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// HomeMenuCell.h
// meituan
//
// Created by jinzelu on 15/6/30.
// Copyright (c) 2015年 jinzelu. All rights reserved.
//

#import <UIKit/UIKit.h>
#import "JZMenuButton.h"


@interface HomeMenuCell : UITableViewCell

-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier menuArray:(NSMutableArray *)menuArray;

@end
144 changes: 144 additions & 0 deletions nuomi/Views/首页/首页/HomeMenuCell.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
//
// HomeMenuCell.m
// meituan
//
// Created by jinzelu on 15/6/30.
// Copyright (c) 2015年 jinzelu. All rights reserved.
//

#import "HomeMenuCell.h"
#import "JZHomepageModel.h"

@interface HomeMenuCell ()<UIScrollViewDelegate>
{
UIView *_backView1;
UIView *_backView2;
UIPageControl *_pageControl;
}

@end

@implementation HomeMenuCell

-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier menuArray:(NSMutableArray *)menuArray{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
//
_backView1 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, screen_width, 160)];
_backView2 = [[UIView alloc] initWithFrame:CGRectMake(screen_width, 0, screen_width, 160)];
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, screen_width, 180)];
scrollView.contentSize = CGSizeMake(2*screen_width, 180);
scrollView.pagingEnabled = YES;
scrollView.delegate = self;
scrollView.showsHorizontalScrollIndicator = NO;

[scrollView addSubview:_backView1];
[scrollView addSubview:_backView2];
[self addSubview:scrollView];



//创建8个
for (int i = 0; i < 16; i++) {
JZHomecategoryModel *categoryM = menuArray[i];
if (i < 4) {
CGRect frame = CGRectMake(i*screen_width/4, 0, screen_width/4, 80);
NSString *title = categoryM.category_name;
// NSString *imageStr = categoryM.category_picurl;
NSString *imageStr = @"icon_homepage_entertainmentCategory";

JZMenuButton *btnView = [[JZMenuButton alloc] initWithFrame:frame];
[btnView setTitle:title forState:UIControlStateNormal];
[btnView setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[btnView setImage:[UIImage imageNamed:imageStr] forState:UIControlStateNormal];
// JZMTBtnView *btnView = [[JZMTBtnView alloc] initWithFrame:frame title:title imageStr:imageStr];
btnView.tag = 10+i;
[_backView1 addSubview:btnView];
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(OnTapBtnView:)];
[btnView addGestureRecognizer:tap];

}else if(i<8){
CGRect frame = CGRectMake((i-4)*screen_width/4, 80, screen_width/4, 80);
NSString *title = categoryM.category_name;
// NSString *imageStr = categoryM.category_picurl;
NSString *imageStr = @"icon_homepage_entertainmentCategory";

JZMenuButton *btnView = [[JZMenuButton alloc] initWithFrame:frame];
[btnView setTitle:title forState:UIControlStateNormal];
[btnView setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[btnView setImage:[UIImage imageNamed:imageStr] forState:UIControlStateNormal];
// JZMTBtnView *btnView = [[JZMTBtnView alloc] initWithFrame:frame title:title imageStr:imageStr];
btnView.tag = 10+i;
[_backView1 addSubview:btnView];
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(OnTapBtnView:)];
[btnView addGestureRecognizer:tap];
}else if(i < 12){
CGRect frame = CGRectMake((i-8)*screen_width/4, 0, screen_width/4, 80);
NSString *title = categoryM.category_name;
// NSString *imageStr = categoryM.category_picurl;
NSString *imageStr = @"icon_homepage_entertainmentCategory";

JZMenuButton *btnView = [[JZMenuButton alloc] initWithFrame:frame];
[btnView setTitle:title forState:UIControlStateNormal];
[btnView setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[btnView setImage:[UIImage imageNamed:imageStr] forState:UIControlStateNormal];
// JZMTBtnView *btnView = [[JZMTBtnView alloc] initWithFrame:frame title:title imageStr:imageStr];
btnView.tag = 10+i;
[_backView2 addSubview:btnView];
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(OnTapBtnView:)];
[btnView addGestureRecognizer:tap];
}else{
CGRect frame = CGRectMake((i-12)*screen_width/4, 80, screen_width/4, 80);
NSString *title = categoryM.category_name;
// NSString *imageStr = categoryM.category_picurl;
NSString *imageStr = @"icon_homepage_entertainmentCategory";

JZMenuButton *btnView = [[JZMenuButton alloc] initWithFrame:frame];
[btnView setTitle:title forState:UIControlStateNormal];
[btnView setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[btnView setImage:[UIImage imageNamed:imageStr] forState:UIControlStateNormal];
// JZMTBtnView *btnView = [[JZMTBtnView alloc] initWithFrame:frame title:title imageStr:imageStr];
btnView.tag = 10+i;
[_backView2 addSubview:btnView];
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(OnTapBtnView:)];
[btnView addGestureRecognizer:tap];
}
}

//
_pageControl = [[UIPageControl alloc] initWithFrame:CGRectMake(screen_width/2-20, 160, 0, 20)];
_pageControl.currentPage = 0;
_pageControl.numberOfPages = 2;
// self.backgroundColor = [UIColor redColor];
[self addSubview:_pageControl];
[_pageControl setCurrentPageIndicatorTintColor:navigationBarColor];
[_pageControl setPageIndicatorTintColor:[UIColor grayColor]];

}
return self;
}

- (void)awakeFromNib {
// Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];

// Configure the view for the selected state
}

-(void)OnTapBtnView:(UITapGestureRecognizer *)sender{
NSLog(@"tag:%ld",sender.view.tag);
}

#pragma mark - UIScrollViewDelegate
-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
CGFloat scrollViewW = scrollView.frame.size.width;
CGFloat x = scrollView.contentOffset.x;
int page = (x + scrollViewW/2)/scrollViewW;
_pageControl.currentPage = page;
}


@end

0 comments on commit c669d28

Please sign in to comment.