//  AppDelegate.m
// UI3_CustomUITableViewCell
//
// Created by zhangxueming on 15/7/15.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import "AppDelegate.h"
#import "ViewController.h" @interface AppDelegate () @end @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
ViewController *root = [[ViewController alloc] init];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:root];
self.window.rootViewController = nav;
self.window.backgroundColor = [UIColor whiteColor]; return YES;
}
//  BookTableViewCell.h
// UI3_CustomUITableViewCell
//
// Created by zhangxueming on 15/7/15.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import <UIKit/UIKit.h>
#import "BookModel.h" @interface BookTableViewCell : UITableViewCell
{
UILabel *_titleLabel;
UILabel *_priceLabel;
UILabel *_detailLabel;
UIImageView *_imageView;
} @property (nonatomic, retain) BookModel *model; @end //
// BookTableViewCell.m
// UI3_CustomUITableViewCell
//
// Created by zhangxueming on 15/7/15.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import "BookTableViewCell.h" @implementation BookTableViewCell - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
_titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(80, 0, 200, 30)];
[self.contentView addSubview:_titleLabel]; _priceLabel = [[UILabel alloc] initWithFrame:CGRectMake(80, 30, 200, 30)];
[self.contentView addSubview:_priceLabel]; _detailLabel = [[UILabel alloc] initWithFrame:CGRectMake(80, 60, 200, 30)];
[self.contentView addSubview:_detailLabel];
_imageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 15, 60, 60)];
[self.contentView addSubview:_imageView];
}
return self;
} - (void)setModel:(BookModel *)model
{
_model = model;
_titleLabel.text = model.bookTitle;
_priceLabel.text = model.bookPrice;
_detailLabel.text = model.bookDetail;
_imageView.image = [UIImage imageNamed:model.imageName];
} - (void)awakeFromNib {
// Initialization code
} - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated]; // Configure the view for the selected state
} @end
//
// BookModel.h
// UI3_CustomUITableViewCell
//
// Created by zhangxueming on 15/7/15.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import <Foundation/Foundation.h> @interface BookModel : NSObject @property (nonatomic, copy)NSString *imageName;
@property (nonatomic, copy)NSString *bookTitle;
@property (nonatomic, copy)NSString *bookPrice;
@property (nonatomic, copy)NSString *bookDetail; @end //
// BookModel.m
// UI3_CustomUITableViewCell
//
// Created by zhangxueming on 15/7/15.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import "BookModel.h" @implementation BookModel @end
//  AdModel.h
// UI3_CustomUITableViewCell
//
// Created by zhangxueming on 15/7/15.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import <Foundation/Foundation.h> @interface AdModel : NSObject @property (nonatomic, copy)NSString *imageName;
@property (nonatomic, copy)NSString *adTitle; @end // AdModel.m
// UI3_CustomUITableViewCell
//
// Created by zhangxueming on 15/7/15.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import "AdModel.h" @implementation AdModel @end
//  AdTableViewCell.h
// UI3_CustomUITableViewCell
//
// Created by zhangxueming on 15/7/15.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import <UIKit/UIKit.h> @interface AdTableViewCell : UITableViewCell <UIScrollViewDelegate>
{
UIScrollView *_scrollView;
UIView *_bgView;
UILabel *_titleLabel;
UIPageControl *_pageControl;
} @property (nonatomic,strong)NSArray *adArray; @end //
// AdTableViewCell.m
// UI3_CustomUITableViewCell
//
// Created by zhangxueming on 15/7/15.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import "AdTableViewCell.h"
#import "AdModel.h" @implementation AdTableViewCell //重写构造方法
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
//创建滚动视图
_scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 375, 160)]; [self.contentView addSubview:_scrollView];
//创建背景视图
_bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 130, 375, 30)];
_bgView.backgroundColor = [UIColor grayColor];
_bgView.alpha = 0.6;
[self.contentView addSubview:_bgView]; //创建titleLabel
_titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10,0, 200, 30)];
_titleLabel.textColor = [UIColor whiteColor];
[_bgView addSubview:_titleLabel]; //创建pageContrl
_pageControl = [[UIPageControl alloc] initWithFrame:CGRectMake(210, 0, 100, 30)];
[_bgView addSubview:_pageControl];
}
return self;
} //分页使能, 该方法一定被执行
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
NSInteger index = _scrollView.contentOffset.x / 375;
_pageControl.currentPage = index;
_titleLabel.text = [[_adArray objectAtIndex:index] adTitle];
} //
- (void)setAdArray:(NSArray *)adArray
{
_adArray = adArray;
for (NSInteger i=0; i<adArray.count; i++) {
AdModel *model = [adArray objectAtIndex:i];
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:model.imageName]];
imageView.frame = CGRectMake(375*i,0, 375, 160);
[_scrollView addSubview:imageView];
}
_scrollView.pagingEnabled = YES;
_scrollView.contentSize = CGSizeMake(375*_adArray.count, 160);
_scrollView.delegate = self; _pageControl.currentPage = 0;
_pageControl.numberOfPages = _adArray.count; _titleLabel.text = [[adArray objectAtIndex:0] adTitle];
} - (void)awakeFromNib {
// Initialization code
} - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated]; // Configure the view for the selected state
} @end
//
// ViewController.h
// UI3_CustomUITableViewCell
//
// Created by zhangxueming on 15/7/15.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import <UIKit/UIKit.h> @interface ViewController : UIViewController <UITableViewDataSource, UITableViewDelegate> @end //
// ViewController.m
// UI3_CustomUITableViewCell
//
// Created by zhangxueming on 15/7/15.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import "ViewController.h"
#import "AdModel.h"
#import "AdTableViewCell.h"
#import "BookModel.h"
#import "BookTableViewCell.h" @interface ViewController ()
{
//表视图
UITableView *_tableView;
//广告数据源
NSMutableArray *_adArray;
//book数据源
NSMutableArray *_dataArray;
}
@end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self creatAdArray];
[self createDataArray];
[self createUI];
} //创建广告数据源
- (void)creatAdArray
{
_adArray = [NSMutableArray array];
for (int i=0; i<4; i++) {
AdModel *model = [[AdModel alloc] init];
NSString *imageName = [NSString stringWithFormat:@"image%i", i];
NSString *title = [NSString stringWithFormat:@"图片%i的标题", i];
model.imageName = imageName;
model.adTitle = title;
[_adArray addObject:model];
}
} //创建book数据源 - (void)createDataArray
{
_dataArray = [NSMutableArray array];
NSString *path = [[NSBundle mainBundle] pathForResource:@"bookData" ofType:@"plist"];
NSArray *array = [NSArray arrayWithContentsOfFile:path];
for (NSDictionary *dict in array) {
BookModel *model = [[BookModel alloc] init];
model.bookTitle = [dict objectForKey:@"title"];
model.bookPrice = [dict objectForKey:@"price"];
model.bookDetail = [dict objectForKey:@"detail"];
model.imageName = [dict objectForKey:@"icon"];
[_dataArray addObject:model];
}
} - (void)createUI
{
_tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 375, 667-64) style:UITableViewStylePlain];
_tableView.delegate = self;
_tableView.dataSource = self;
[self.view addSubview:_tableView];
} #pragma mark ---UITableViewDataSource--- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
} - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return _dataArray.count+1;
} - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.row==0) {
static NSString *adCellId = @"adCell";
AdTableViewCell *cell =[tableView dequeueReusableCellWithIdentifier:adCellId];
if (!cell) {
cell = [[AdTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:adCellId];
}
//cell.frame = CGRectMake(0, 0, 375, 160);
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.adArray = _adArray;
return cell;
}
else
{
static NSString *bookCellId = @"bookCell";
BookTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:bookCellId];
if (!cell) {
cell = [[BookTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:bookCellId];
}
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.model = [_dataArray objectAtIndex:indexPath.row-1];
return cell;
}
} - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.row == 0) {
return 160;
}
else
{
return 90;
}
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} @end

UI3_CustomUITableViewCell的更多相关文章

随机推荐

  1. 使用PageHeap.EXE或GFlags.EXE检查内存越界错误 (转)

    2011-05-27 20:19 290人阅读 评论(0) 收藏 举报 microsoftdebuggingstructureoutputimagefile 必先利其器之一:使用PageHeap.EX ...

  2. SpringMVC 源码深度解析&lt;context:component-scan&gt;(扫描和注冊的注解Bean)

    我们在SpringMVC开发项目中,有的用注解和XML配置Bean,这两种都各有自己的优势,数据源配置比較经经常使用XML配置.控制层依赖的service比較经经常使用注解等(在部署时比較不会改变的) ...

  3. PrettyProgressBar

    https://github.com/liuguangqiang/PrettyProgressBar

  4. HTML之一 符号实体

    符号实体和”语言代码“以及”字符集“无关.

  5. 浅谈模块化的JavaScript

    模块化JavaScript之风早已席卷而来, CommonJS . AMD . NodeJS .RequireJS . SeaJS . curljs  等模块化的JavaScript概念及库扑面而来, ...

  6. # 36氪开放日 • 杭州 • 11月10日 # 谈谈参会感受

           今天下午,第一次去参加了36氪的开放日,虽然站着听有点累,但是也很值得.会上很多创业者都分享和展示了他们的产品,一方面自己了解了一些产品人的故事,另一方面也对如何做产品有了新的认识.参会 ...

  7. 云服务器 ECS Linux IO 占用高问题排查方法

    https://help.aliyun.com/knowledge_detail/41224.html?spm=5176.7841174.2.19.uqC1as#使用 iostat 从系统纬度查看磁盘 ...

  8. Linux内存管理学习笔记 转

    https://yq.aliyun.com/articles/11192?spm=0.0.0.0.hq1MsD 随着要维护的服务器增多,遇到的各种稀奇古怪的问题也会增多,要想彻底解决这些“小”问题往往 ...

  9. 开始研究Ray tracing

    几个月前面试时Boss问过我一个问题--"除了scanline渲染方法,你还知道什么其他渲染方式?",我没答出来,至今记忆犹新. 前段时间摆弄Intel VTune时看了它的示例代 ...

  10. Spark目录

    1. Spark1.0.0 应用程序部署工具spark-submit 2. Spark Streaming的编程模型 3. 使用java api操作HDFS文件 4. 用SBT编译Spark的Word ...