//  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. [NOIP 2014复习]第三章:动态规划——NOIP历届真题回想

    背包型动态规划 1.Wikioi 1047 邮票面值设计 题目描写叙述 Description 给定一个信封,最多仅仅同意粘贴N张邮票,计算在给定K(N+K≤40)种邮票的情况下(假定全部的邮票数量都 ...

  2. Android上的SQLLite性能分析

    也许有人还不知道,Android 是有一些内建的 类库支持 SQL Lite 数据库的操作.他提供了一个很好的方式在 Android 上组织少量的数据.不管怎样,在使用这些类库的时候有一些陷阱是需要注 ...

  3. iOS开发——实用技术OC篇&事件处理详解

    事件处理详解 一:事件处理 事件处理常见属性: 事件类型 @property(nonatomic,readonly) UIEventType     type; @property(nonatomic ...

  4. iOS开发——多线程OC篇&多线程总结

    多线程总结 //1.NSThread /** 优点:NSThread 比其他两个轻量级. 缺点:需要自己管理线程的生命周期,线程同步,线程同步时对数据的加锁会有一定的系统开销. cocoa给我提供了两 ...

  5. LINUX O_Direact

    http://laokaddk.blog.51cto.com/368606/699563

  6. Ogre Addon之Paged Geometry

    还是OGRE好啊,无尽的Addon,无尽的宝藏.既有SkyX,Hydrx这样的天空水体渲染库可供学习,还有Paged Geometry这样的“大规模海量geometry管理系统”.它通过batch,s ...

  7. Bash脚本编程基础

    为实现某个任务,将许多命令组合后,写入一个可执行的文本文件的方法,称为Shell脚本编程. 按照应用的Shell环境不同,可以将Shell脚本分为多种类型.其中最常见的是应用于Bash和Tcsh的脚本 ...

  8. Anatomy of the Linux kernel--转

    ref:http://www.ibm.com/developerworks/linux/library/l-linux-kernel/?S_TACT=105AGX52&S_CMP=cn-a-l ...

  9. 如何使用NSOperations和NSOperationQueues(二)

    "每一个应用程序至少有一个主线程.线程的工作就是去执行一系列的指令.在Cocoa Touch中,主线程包含应用程序的主运行回路.几乎所有你写的代码都会在主线程中执行,除非你特别创建" ...

  10. iOS 生成随机数 重复 不重复

    //编程的时候,有三条任选执行路径,都会显示一些图片,比如路径1显示的图片是一个人,路径2显示的是两个人,路径3显示任意人数的图片,要求每次进入该页面都不能重复初始的那张图片. 于是我想到了 运用随机 ...