//  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. Mac下配置cocos2d-x开发环境(android和ios)

    一.下载cocos2d-x http://cocos2d-x.org/projects/cocos2d-x/wiki/Download cocos2d-x-2.1.4.zip @ June.18, 2 ...

  2. 使用NIO提升性能

    NIO是New I/O的简称,与旧式的基于流的I/O方法相对,从名字看,它表示新的一套Java I/O标准. 具有以下特性: 传统Java IO,它是阻塞的,低效的.那么Java NIO和传统Java ...

  3. Golang学习 - unicode/utf8 包

    ------------------------------------------------------------ // 编码所需的基本数字 const ( RuneError = '\uFFF ...

  4. linux用户权限

    Linux下passwd和shadow文件内容详解 一./etc/passwd/etc/passwd 文件是一个纯文本文件,每行采用了相同的格式: name:password:uid:gid:comm ...

  5. ubuntu11.04编译TQ2440 Qt2.2.0 成功

    转:http://blog.csdn.net/xuehui869/article/details/8958311 运行主机:ubuntu 32位 11.04QT版本:2.2.0开发板:TQ2440源码 ...

  6. Squish License

    https://www.froglogic.com/squish/gui-testing/prices-and-licensing/index.php Prices and Licensing Who ...

  7. C#三大支柱之多态

    1.包含与委托---has-a 2.嵌套类型(枚举.类.接口.结构等) 由于只有嵌套类才可声明为私有,通过嵌套类则可以完全控制内部类型的访问级别. 嵌套类型是包含类的成员,所有可以访问包含类的私有成员 ...

  8. iOS中通知中心NSNotificationCenter应用总结

    通知中心(NSNotificationCenter)实际是在程序内部提供了一种广播机制.把接收到的消息,根据内部的消息转发表,将消息转发给需要的对象.这句话其实已经很明显的告诉我们要如何使用通知了.第 ...

  9. 《Cortex-M0权威指南》之体系结构---系统模型

    转载请注明来源:cuixiaolei的技术博客 Cortex-M0体系结构包括:系统模型.存储器映射.异常中断.这篇文章主要讲解Cortex-M0的系统模型. 操作模式和状态 如上图所示,Cortex ...

  10. php实现签到功能

    首先我在数据库里建了两张表,一个是用户的积分表,一个是签到状态表,分来用来记录用户的积分数和先到状态 在用户签到状态表中我们有一个字段,last_sign_time,即上一次签到时间,每次可以签到的时 ...