//  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. XCode7,打包上传的一些警告,及参考处理方法

    1.ERROR ITMS-90046 /90085: "Invalid Code Signing Entitlements. Your application bundle's signat ...

  2. 你真的会使用SQL Server的备份还原功能吗?之二:主要备份类型

    假设在下面几个时间段中,一个数据库积累插入了如下数据: 1.完整数据库备份 故名思意,完整数据库备份包括完整的数据库信息.它包括数据库的数据文件和备份结尾的部份活动事务日志. 完整备份基本语法如下: ...

  3. 剑指 offer set 1 二维数组中查找

    总结 1. 二维数组搜索题遇到两个了, 一个是 Leetcode 上 search in 2D matrix. 那道题比较简单, 因为下一行的所有元素大于上一行的. 这道题对二维矩阵的要求比较松, 起 ...

  4. Flex+Struts2+JSON实现Flex和后台的HTTP Service请求

    http://www.fengfly.com/plus/view-191093-1.html Flex+Struts2+JSON的后台代码我在这就不多说了.不懂得请看我写的上一篇文章<Strut ...

  5. Linux内核分析笔记 与Linux内核开发理论

    http://www.cnblogs.com/hanyan225/category/308793.html

  6. Javascript实现鼠标框选元素后拖拽被框选的元素

    之前需要做一个框选元素后拖拽被框选中的元素功能,在网上找资料做了一些修改,基本达到了需要的效果,希望对也需要实现框选后拖拽元素功能的人有用. 页面加载后效果 框选后的内容可以拖拽,如下图: 代码下载

  7. BM25相关度打分公式

    BM25算法是一种常见用来做相关度打分的公式,思路比较简单,主要就是计算一个query里面所有词和文档的相关度,然后在把分数做累加操作,而每个词的相关度分数主要还是受到tf/idf的影响.公式如下: ...

  8. 标准库 - fmt/print.go 解读

    // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a B ...

  9. Golang学习 - fmt 包

    ------------------------------------------------------------ // Print 将参数列表 a 中的各个参数转换为字符串并写入到标准输出中. ...

  10. mysql中的longblob类型处理

    longblob 对应的 C#数据类型为 byte[] 1.byte[] 与 string 之间的转换 byte[] bb = Encoding.UTF8.GetBytes(ss); string s ...