Skip to content

Commit

Permalink
新增cell
Browse files Browse the repository at this point in the history
  • Loading branch information
lookingstars committed Sep 28, 2015
1 parent c669d28 commit 4c4a9d4
Show file tree
Hide file tree
Showing 7 changed files with 312 additions and 9 deletions.
12 changes: 12 additions & 0 deletions nuomi.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
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 */; };
E3A3FB101BB54B4A000E9729 /* JZAlbumCell.m in Sources */ = {isa = PBXBuildFile; fileRef = E3A3FB0F1BB54B4A000E9729 /* JZAlbumCell.m */; };
E3A3FB131BB8E02E000E9729 /* JZHomeBlock2Cell.m in Sources */ = {isa = PBXBuildFile; fileRef = E3A3FB121BB8E02E000E9729 /* JZHomeBlock2Cell.m */; };
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 @@ -234,6 +236,10 @@
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>"; };
E3A3FB0E1BB54B4A000E9729 /* JZAlbumCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JZAlbumCell.h; sourceTree = "<group>"; };
E3A3FB0F1BB54B4A000E9729 /* JZAlbumCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JZAlbumCell.m; sourceTree = "<group>"; };
E3A3FB111BB8E02E000E9729 /* JZHomeBlock2Cell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JZHomeBlock2Cell.h; sourceTree = "<group>"; };
E3A3FB121BB8E02E000E9729 /* JZHomeBlock2Cell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JZHomeBlock2Cell.m; 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 @@ -1075,6 +1081,8 @@
E3B7F23D1BB3CDDE001F4E16 /* 首页 */ = {
isa = PBXGroup;
children = (
E3A3FB0E1BB54B4A000E9729 /* JZAlbumCell.h */,
E3A3FB0F1BB54B4A000E9729 /* JZAlbumCell.m */,
E3A3FB091BB52BCF000E9729 /* HomeMenuCell.h */,
E3A3FB0A1BB52BCF000E9729 /* HomeMenuCell.m */,
E3B7F23F1BB3CE8C001F4E16 /* JZHomeShopCell.h */,
Expand All @@ -1083,6 +1091,8 @@
E3B7F2431BB3CEC9001F4E16 /* JZHomeNewCell.m */,
E3B7F2451BB3DC04001F4E16 /* JZHomeJingxuanCell.h */,
E3B7F2461BB3DC04001F4E16 /* JZHomeJingxuanCell.m */,
E3A3FB111BB8E02E000E9729 /* JZHomeBlock2Cell.h */,
E3A3FB121BB8E02E000E9729 /* JZHomeBlock2Cell.m */,
);
path = "首页";
sourceTree = "<group>";
Expand Down Expand Up @@ -1453,10 +1463,12 @@
files = (
E3B7F0631BB23600001F4E16 /* ViewController.m in Sources */,
E3A3FB051BB4DF88000E9729 /* JZHomepageModel.m in Sources */,
E3A3FB101BB54B4A000E9729 /* JZAlbumCell.m in Sources */,
E3B7F2471BB3DC04001F4E16 /* JZHomeJingxuanCell.m in Sources */,
E3A3FB0B1BB52BCF000E9729 /* HomeMenuCell.m in Sources */,
E3B7F2441BB3CEC9001F4E16 /* JZHomeNewCell.m in Sources */,
E3B7F0E71BB2A8AF001F4E16 /* JZBaseTabBarViewController.m in Sources */,
E3A3FB131BB8E02E000E9729 /* JZHomeBlock2Cell.m in Sources */,
E3B7F2501BB3E90F001F4E16 /* OPDataResponse.m in Sources */,
E3B7F0601BB23600001F4E16 /* AppDelegate.m in Sources */,
E3B7F2381BB3C866001F4E16 /* JZHomeViewController.m in Sources */,
Expand Down
Binary file not shown.
40 changes: 31 additions & 9 deletions nuomi/Controller/首页/JZHomeViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
#import "JZHomeShopModel.h"
#import "JZHomepageModel.h"
#import "HomeMenuCell.h"
#import "JZAlbumCell.h"
#import "JZHomeBlock2Cell.h"

@interface JZHomeViewController ()<UITableViewDataSource, UITableViewDelegate>
@interface JZHomeViewController ()<UITableViewDataSource, UITableViewDelegate,JZAlbumDelegate,JZHomeBlock2Delegate>

@property (weak, nonatomic) IBOutlet UILabel *cityNameLabel;

Expand Down Expand Up @@ -153,7 +155,11 @@ -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPat
}else if (indexPath.row == 2){
return 80;
}else if (indexPath.row == 3){
return 240;
if (_specialModel.block_2) {
return [JZHomeBlock2Cell tableView:tableView heightForRowAtIndexPath:indexPath withArray:_specialModel.block_2];
}else{
return 5;
}
}else if (indexPath.row == 4){
return 132;
}else if (indexPath.row == 5){
Expand Down Expand Up @@ -191,23 +197,31 @@ -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NS
return cell;
}else if (indexPath.row == 3){
static NSString *cellIndentifier = @"cell3";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIndentifier];
JZHomeBlock2Cell *cell = [tableView dequeueReusableCellWithIdentifier:cellIndentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIndentifier];
if (_specialModel.block_2) {
cell = [[JZHomeBlock2Cell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIndentifier array:_specialModel.block_2];
}else{
cell = [[JZHomeBlock2Cell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIndentifier];
}
}

cell.textLabel.text = @"";
// cell.textLabel.text = @"块";
//赋值
cell.delegate = self;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}else if (indexPath.row == 4){
static NSString *cellIndentifier = @"cell4";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIndentifier];
JZAlbumCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIndentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIndentifier];
cell = [[JZAlbumCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIndentifier frame:CGRectMake(0, 0, screen_width, 132)];
}
if (_specialModel.block_3) {
[cell setSpecialArray:_specialModel.block_3];
}

cell.textLabel.text = @"滑动";
//赋值
cell.delegate = self;
return cell;
}else if (indexPath.row == 5){
static NSString *cellIndentifier = @"normalCell";
Expand Down Expand Up @@ -240,7 +254,15 @@ -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *
}


#pragma mark - **************** JZAlbumDelegate
-(void)didSelectedAlbumAtIndex:(NSInteger)index {
NSLog(@"index:%ld",index);
}

#pragma mark - **************** JZHomeBlock2Delegate
-(void)didSelectedHomeBlock2AtIndex:(NSInteger)index{
NSLog(@"block2 index:%ld",index);
}


/*
Expand Down
26 changes: 26 additions & 0 deletions nuomi/Views/首页/首页/JZAlbumCell.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//
// JZAlbumCell.h
// chuanke
//
// Created by jinzelu on 15/7/23.
// Copyright (c) 2015年 jinzelu. All rights reserved.
//

#import <UIKit/UIKit.h>

@protocol JZAlbumDelegate <NSObject>

@optional
-(void)didSelectedAlbumAtIndex:(NSInteger)index;

@end

@interface JZAlbumCell : UITableViewCell

@property(nonatomic, strong) NSArray *specialArray;/**< 数据源数组 */

@property(nonatomic, assign) id<JZAlbumDelegate> delegate;

-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier frame:(CGRect)frame;

@end
102 changes: 102 additions & 0 deletions nuomi/Views/首页/首页/JZAlbumCell.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
//
// JZAlbumCell.m
// chuanke
//
// Created by jinzelu on 15/7/23.
// Copyright (c) 2015年 jinzelu. All rights reserved.
//

#import "JZAlbumCell.h"
#import "UIImageView+WebCache.h"

@interface JZAlbumCell ()
{
UIScrollView *_scrollView;
}

@end

@implementation JZAlbumCell

-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier frame:(CGRect)frame{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
//创建scrollview
_scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(5, 0, frame.size.width, frame.size.height)];
_scrollView.showsHorizontalScrollIndicator = NO;
[self addSubview:_scrollView];

//添加图片
for (int i = 0; i < 10; ++i) {
CGFloat width = screen_width*2/7;
//
UIView *backView = [[UIView alloc] initWithFrame:CGRectMake((screen_width*2/7+5)*i, 0, width, frame.size.height)];
backView.tag = 80+i;
backView.userInteractionEnabled = YES;
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(OnTapImage:)];
[backView addGestureRecognizer:tap];
[_scrollView addSubview:backView];

//
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(width/2-25, 5, 50, 50)];
imageView.tag = i+20;
[backView addSubview:imageView];

//大标题
UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, frame.size.height/2+5, width, 25)];
titleLabel.font = [UIFont systemFontOfSize:15];
titleLabel.tag = 40+i;
titleLabel.textAlignment = NSTextAlignmentCenter;
titleLabel.textColor = RGB(34, 34, 34);
[backView addSubview:titleLabel];

//小标题
UILabel *subtitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, frame.size.height/2+5+25, width, 25)];
subtitleLabel.font = [UIFont systemFontOfSize:13];
subtitleLabel.tag = 60 + i;
subtitleLabel.textAlignment = NSTextAlignmentCenter;
subtitleLabel.textColor = RGB(100, 100, 100);
[backView addSubview:subtitleLabel];
}

}
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)setSpecialArray:(NSArray *)specialArray {
CGFloat width = screen_width*2/7;
_scrollView.contentSize = CGSizeMake((width+5)*specialArray.count+5, _scrollView.frame.size.height);
for (int i = 0; i < specialArray.count; i++) {
if (i == 10) {
return;
}
UIImageView *imageView = (UIImageView *)[_scrollView viewWithTag:20+i];
UILabel *titleLabel = (UILabel *)[_scrollView viewWithTag:40+i];
UILabel *subtitleLabel = (UILabel *)[_scrollView viewWithTag:60+i];

NSString *imgStr = [specialArray[i] objectForKey:@"picture_url"];
[imageView sd_setImageWithURL:[NSURL URLWithString:imgStr] placeholderImage:[UIImage imageNamed:@"ugc_photo"]];
titleLabel.text = [specialArray[i] objectForKey:@"adv_title"];
subtitleLabel.text = [specialArray[i] objectForKey:@"adv_subtitle"];
}
}

-(void)OnTapImage:(UITapGestureRecognizer *)sender{
UIView *backView = (UIView *)sender.view;
int tag = (int)backView.tag-80;
[self.delegate didSelectedAlbumAtIndex:tag];
}


@end
26 changes: 26 additions & 0 deletions nuomi/Views/首页/首页/JZHomeBlock2Cell.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//
// JZHomeBlock2Cell.h
// nuomi
//
// Created by jinzelu on 15/9/28.
// Copyright (c) 2015年 jinzelu. All rights reserved.
//

#import <UIKit/UIKit.h>

@protocol JZHomeBlock2Delegate <NSObject>

@optional
-(void)didSelectedHomeBlock2AtIndex:(NSInteger)index;

@end

@interface JZHomeBlock2Cell : UITableViewCell

@property (nonatomic, assign) id<JZHomeBlock2Delegate> delegate;

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier array:(NSArray *)array;


+(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath withArray:(NSArray *)array;
@end
Loading

0 comments on commit 4c4a9d4

Please sign in to comment.