//  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. 支付宝api指南

    tyle="margin:20px 0px 0px; line-height:26px; font-family:Arial"> 在这些服务中,服务类型大致可以分为以下几类: ...

  2. CustomProgressBar

    https://github.com/eltld/CustomProgressBar-master

  3. [AngularJS] Best Practise - Minification and annotation

    Annotation Order: It's considered good practice to dependency inject Angular's providers in before o ...

  4. [Express] Level 3: Reading from the URL

    City Search We want to create an endpoint that we can use to filter cities. Follow the tasks below t ...

  5. android 自定义ViewGroup和对view进行切图动画实现滑动菜单SlidingMenu

    示意图就不展示了,和上一节的一样,滑动菜单SlidingMenu效果如何大家都比较熟悉,在这里我简单说明一下用自定义ViewGroup来实现. 实现方法:我们自定义一个ViewGroup实现左右滑动, ...

  6. 使用ActivityGroup来切换Activity和Layout

    前言 在一个主界面中做Activity切换一般都会用TabActivity,使用方便,Activity互相之间相对独立,但是可定制性不强,而且修改起来很麻烦.当然也可以把layout分开,把逻辑代码全 ...

  7. 设备文件的创建mknod

    设备文件是通过mknod命令来创建的.其命令格式为: mknod [OPTION]... NAME TYPE [MAJOR MINOR] TYPE取值: 主设备号和次设备号两个参数合并成一个16位的无 ...

  8. 认清Linux中标准输入和标准输出的双重含义

    按照惯例,UNIX系统shell使用文件描述符0与进程的标准输入(一般是键盘)相关联,文件描述符1与标准输出(一般是显示器)相关联,文件描述符2与标准出错输出(一般是显示器)相关联. 在依从POSIX ...

  9. Topology: The Architecture of Distributed Systems--reference

    reference:http://blog.couchbase.com/topology-architecture-distributed-systems You can’t judge a book ...

  10. Android基本控件之listView(三)<用ListView实现分页加载>

    我们之前讨论了ListView的基本使用方法和ListView的优化 今天我们再来讨论一个关于ListView的一个新的东西~就是分页加载.那么什么是分页加载呢?简单点说,就是"下拉刷新&q ...