UI-Day12____Cell

2015.3.31

#import "ViewController.h"

#import "BookCell.h"

#import "AdCell.h"

@interface ViewController ()<UITableViewDelegate,UITableViewDataSource>

{

NSMutableArray *_dataArr;

UITableView *_myTableView;

}

@end

@implementation ViewController

- (void)viewDidLoad

{

[super viewDidLoad];

// Do any additional setup after loading the view, typically from a nib.

[self createData];

[self createUI];

}

-(void)createData

{

//通过文件名,找到文件路径

NSString *path=[[NSBundle mainBundle]pathForResource:@"bookData" ofType:@"plist"];

//通过文件路径,读取文件内容(接收的容器需要和文件最外层的结构匹配)

NSArray *fileArr=[NSArray arrayWithContentsOfFile:path];

_dataArr =[[NSMutableArray alloc]init];

for (NSDictionary *dic in fileArr) {

BookModel *bm=[[BookModel alloc]init];

bm.icon=[dic objectForKey:@"icon"];

bm.price=[dic objectForKey:@"price"];

bm.title=[dic objectForKey:@"title"];

bm.detail=[dic objectForKey:@"detail"];

[_dataArr addObject:bm];

}

}

-(void)createUI

{

_myTableView =[[UITableView alloc]initWithFrame:self.view.bounds];

_myTableView.delegate=self;

_myTableView.dataSource=self;

[self.view addSubview:_myTableView];

}

#pragma mark - tableView

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

{

return [_dataArr count]+1;

}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

{

if (!indexPath.row) {

return 160;

}

return 80;

}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

if (!indexPath.row) {

static NSString *[email protected]"asdf";

AdCell *ad=[tableView dequeueReusableCellWithIdentifier:adId];

if (!ad) {

ad=[[AdCell alloc]initWithStyle:0 reuseIdentifier:adId];

}

return ad;

}

static NSString *[email protected]"cellID";

BookCell *cell=[tableView dequeueReusableCellWithIdentifier:identifier];

if (!cell) {

cell=[[BookCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];

}

BookModel *bm=[_dataArr objectAtIndex:indexPath.row-1];

[cell setContentsWithBookModel:bm];

return cell;

}

- (void)didReceiveMemoryWarning

{

[super didReceiveMemoryWarning];

// Dispose of any resources that can be recreated.

}

@end

#import <UIKit/UIKit.h>

@interface AdCell : UITableViewCell <UIScrollViewDelegate>

@end

#import "AdCell.h"

@implementation AdCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier

{

self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];

if (self) {

// Initialization code

[self createUI];

}

return self;

}

-(void)createUI

{

UIScrollView *sv = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, 320, 160)];

[self.contentView addSubview:sv];

[sv setContentOffset:CGPointMake(320, 0)];

for (int i=0; i<4; i++) {

UIImageView *iv = [[UIImageView alloc]initWithFrame:CGRectMake(320*(i+1), 0, 320, 160)];

iv.image = [UIImage imageNamed:[NSString stringWithFormat:@"image%d",i]];

iv.userInteractionEnabled = YES;

UITapGestureRecognizer *tapGR = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapGR:)];

[iv addGestureRecognizer:tapGR];

tapGR.view.tag = 10+i;

[sv addSubview:iv];

}

UIImageView *pre = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 320, 160)];

pre.image = [UIImage imageNamed:@"image3"];

[sv addSubview:pre];

UIImageView *next = [[UIImageView alloc]initWithFrame:CGRectMake(320*5, 0, 320, 160)];

next.image = [UIImage imageNamed:@"image0"];

[sv addSubview:next];

sv.showsHorizontalScrollIndicator = NO;

sv.contentSize = CGSizeMake(320*6, 160);

sv.pagingEnabled = YES;

sv.delegate = self;

UIPageControl *pc = [[UIPageControl alloc]initWithFrame:CGRectMake(230, 140, 100, 20)];

pc.numberOfPages = 4;

pc.tag = 100;

[self.contentView addSubview:pc];

}

- (void)tapGR:(UITapGestureRecognizer *)tapGR

{

UIAlertView *av = [[UIAlertView alloc]initWithTitle:nil message:[NSString stringWithFormat:@"%d",tapGR.view.tag-9] delegate:self cancelButtonTitle:@"NO" otherButtonTitles:@"YES", nil];

[av show];

}

-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView

{

UIPageControl *pc = (UIPageControl *)[self.contentView viewWithTag:100];

NSInteger page=scrollView.contentOffset.x/320;

if (!page) {

[scrollView setContentOffset:CGPointMake(320*4, 0)];

pc.currentPage=4;

}

else if (page==5) {

[scrollView setContentOffset:CGPointMake(320, 0)];

pc.currentPage=0;

}else

{

pc.currentPage=page-1;

}

}

- (void)awakeFromNib

{

// Initialization code

}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated

{

[super setSelected:selected animated:animated];

// Configure the view for the selected state

}

@end

#import <Foundation/Foundation.h>

@interface BookModel : NSObject

@property (nonatomic,copy)NSString *detail;

@property (nonatomic,copy)NSString *icon;

@property (nonatomic,copy)NSString *price;

@property (nonatomic,copy)NSString *title;

@end

#import "BookModel.h"

@implementation BookModel

@end

#import <UIKit/UIKit.h>

#import "BookModel.h"

@interface BookCell : UITableViewCell

{

UIImageView *_iconView;//头像

UILabel *_titleLabel;//标题

UILabel *_priceLabel;//价格

UILabel *_detailLabel;//详情

}

//

-(void)setContentsWithBookModel:(BookModel *)bm;

@end

#import "BookCell.h"

@implementation BookCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier

{

self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];

if (self) {

// Initialization code

[self createUI];

}

return self;

}

-(void)createUI

{

_iconView=[[UIImageView alloc]initWithFrame:CGRectMake(10, 10, 60, 60)];

[self.contentView addSubview:_iconView];

_titleLabel=[[UILabel alloc]initWithFrame:CGRectMake(90, 5, 200, 25)];

_titleLabel.font=[UIFont systemFontOfSize:16];

[self.contentView addSubview:_titleLabel];

_priceLabel=[[UILabel alloc]initWithFrame:CGRectMake(90, 30, 200, 25)];

_priceLabel.font=[UIFont systemFontOfSize:14];

[self.contentView addSubview:_priceLabel];

_detailLabel=[[UILabel alloc]initWithFrame:CGRectMake(90, 55, 200, 25)];

_detailLabel.font=[UIFont systemFontOfSize:14];

[self.contentView addSubview:_detailLabel];

}

-(void)setContentsWithBookModel:(BookModel *)bm

{

_iconView.image=[UIImage imageNamed:bm.icon];

_titleLabel.text=bm.title;

_priceLabel.text=bm.price;

_detailLabel.text=bm.detail;

}

- (void)awakeFromNib

{

// Initialization code

}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated

{

[super setSelected:selected animated:animated];

// Configure the view for the selected state

}

@end

————————————————————————————分割————————————————————————————

  

#import "ViewController.h"

#import "BookCell.h"

#import "BookModel.h"

@interface ViewController () <UITableViewDataSource, UITableViewDelegate>

{

NSMutableArray *_dataArr;

UITableView *_myTableView;

}

@end

@implementation ViewController

- (void)viewDidLoad

{

[super viewDidLoad];

// Do any additional setup after loading the view, typically from a nib.

[self createData];

[self createUI];

}

- (void)createData

{

NSString *path = [[NSBundle mainBundle] pathForResource:@"bookData" ofType:@"plist"];

NSArray *fileArr = [NSArray arrayWithContentsOfFile:path];

_dataArr = [[NSMutableArray alloc] init];

for (NSDictionary *dic in fileArr) {

BookModel *bm = [[BookModel alloc] init];

bm.icon = [dic objectForKey:@"icon"];

bm.title = [dic objectForKey:@"title"];

bm.price = [dic objectForKey:@"price"];

bm.detail = [dic objectForKey:@"detail"];

[_dataArr addObject:bm];

}

}

- (void)createUI

{

_myTableView = [[UITableView alloc] initWithFrame:self.view.bounds];

_myTableView.dataSource = self;

_myTableView.delegate = self;

[self.view addSubview:_myTableView];

}

#pragma mark - tableView

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

{

return [_dataArr count];

}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

{

return 80;

}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

BookCell *cell = [tableView dequeueReusableCellWithIdentifier:@"qqq"];

if (!cell) {

//通过nib文件加载cell

cell = [[[NSBundle mainBundle] loadNibNamed:@"BookCell" owner:self options:nil] lastObject];

}

BookModel *bm = [_dataArr objectAtIndex:indexPath.row];

cell.iconView.image = [UIImage imageNamed:bm.icon];

cell.titleLabel.text = bm.title;

cell.priceLabel.text = bm.price;

cell.detailLabel.text = bm.detail;

return cell;

}

- (void)didReceiveMemoryWarning

{

[super didReceiveMemoryWarning];

// Dispose of any resources that can be recreated.

}

@end

#import <Foundation/Foundation.h>

@interface BookModel : NSObject

@property (nonatomic, copy) NSString *icon;

@property (nonatomic, copy) NSString *title;

@property (nonatomic, copy) NSString *price;

@property (nonatomic, copy) NSString *detail;

@end

#import "BookModel.h"

@implementation BookModel

@end

#import <UIKit/UIKit.h>

@interface BookCell : UITableViewCell

@property (weak, nonatomic) IBOutlet UIImageView *iconView;

@property (weak, nonatomic) IBOutlet UILabel *titleLabel;

@property (weak, nonatomic) IBOutlet UILabel *priceLabel;

@property (weak, nonatomic) IBOutlet UILabel *detailLabel;

@end

#import "BookCell.h"

@implementation BookCell

- (void)awakeFromNib

{

// Initialization code

}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated

{

[super setSelected:selected animated:animated];

// Configure the view for the selected state

}

@end

————————————————————————————分割————————————————————————————

改动

#import "ViewController.h"

#import "BookCell.h"

#import "BookModel.h"

@interface ViewController () <UITableViewDataSource, UITableViewDelegate>

{

NSMutableArray *_dataArr;

UITableView *_myTableView;

}

@end

@implementation ViewController

- (void)viewDidLoad

{

[super viewDidLoad];

// Do any additional setup after loading the view, typically from a nib.

[self createData];

[self createUI];

}

- (void)createData

{

NSString *path = [[NSBundle mainBundle] pathForResource:@"bookData" ofType:@"plist"];

NSArray *fileArr = [NSArray arrayWithContentsOfFile:path];

_dataArr = [[NSMutableArray alloc] init];

for (NSDictionary *dic in fileArr) {

BookModel *bm = [[BookModel alloc] init];

bm.icon = [dic objectForKey:@"icon"];

bm.title = [dic objectForKey:@"title"];

bm.price = [dic objectForKey:@"price"];

bm.detail = [dic objectForKey:@"detail"];

[_dataArr addObject:bm];

}

}

- (void)createUI

{

_myTableView = [[UITableView alloc] initWithFrame:self.view.bounds];

_myTableView.dataSource = self;

_myTableView.delegate = self;

[self.view addSubview:_myTableView];

//通过文件名找到nib

UINib *cellNib = [UINib nibWithNibName:@"BookCell" bundle:nil];

//tv注册cell(将tv和cell关联起来)

[_myTableView registerNib:cellNib forCellReuseIdentifier:@"qqq"];

}

#pragma mark - tableView

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

{

return [_dataArr count];

}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

{

return 80;

}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

BookCell *cell = [tableView dequeueReusableCellWithIdentifier:@"qqq" forIndexPath:indexPath];

BookModel *bm = [_dataArr objectAtIndex:indexPath.row];

cell.iconView.image = [UIImage imageNamed:bm.icon];

cell.titleLabel.text = bm.title;

cell.priceLabel.text = bm.price;

cell.detailLabel.text = bm.detail;

return cell;

}

- (void)didReceiveMemoryWarning

{

[super didReceiveMemoryWarning];

// Dispose of any resources that can be recreated.

}

@end

时间: 2024-10-13 16:01:37

UI-Day12____Cell的相关文章

基于jquery开发的UI框架整理分析

根据调查得知,现在市场中的UI框架差不多40个左右,不知大家都习惯性的用哪个框架,现在市场中有几款UI框架稍微的成熟一些,也是大家比较喜欢的一种UI框架,那应该是jQuery,有部分UI框架都是根据jQuery研发出来的产品,现在也很常见了. 国产jQuery UI框架 (jUI) DWZ DWZ富客户端框架(jQuery RIA framework), 是中国人自己开发的基于jQuery实现的Ajax RIA开源框架.设计目标是简单实用,快速开发,降低ajax开发成本. jQuery 部件布局

iOS instruments之ui automation的简单使用(高手绕道)

最近使用了几次instruments中的automation工具,现记录下automation的简单使用方法,希望对没接触过自动化测试又有需求的人有所帮助.  UI 自动测试是iOS 中重要的附加功能,它由名为"Automation"的新的工具对象支持.Automation工具的脚本是用JavaScript语言编写,主要用于分析应用的性能和用户行为,模仿/击发被请求的事件,利用它可以完成对被测应用的简单的UI测试及相关功能测试. 一. 简单的录制脚本 打开xcode,这里用我为我家亲爱

RDVECore来自锐动的无UI,高度抽象化API的视频编辑SDK--IOS版

1 编写目的 预期读者: 有视频编辑开发经验或者无经验的,打算或者正在使用"锐动IOS版RDVECore"的相关工程师. iOS软件工程师. 产品经理. QA 2 名词解释 分辨率:用于计算机视频处理的图像,以水平和垂直方向上所能显示的像素数来表示分辨率.常见视频分辨率的有1080P即1920x1080,720P即1080x720,640x480等. 帧率:每秒的帧数(fps)或者说帧率表示图形处理器处理场时每秒钟能够更新的次数. 码率: 数据传输时单位时间传送的数据位数,一般我们用的

UI渲染回顾简单笔记

UI渲染的简单过程: CPU,GPU,显示器协同工作,CPU 中计算显示内容,比如视图的创建.布局计算.图片解码.文本绘制等,然后将计算结果提交给GPU,由 GPU 进行变换.合成.渲染.随后 GPU 会把渲染结果提交到帧缓冲区去,随后等待下一次 VSync(垂直同步信号) 到来时,视频控制器会逐行读取帧缓冲区的数据,经过可能的数模转换传递给显示器显示.由于垂直同步的机制,如果在一个 VSync 时间内,CPU 或者 GPU 没有完成内容提交,则那一帧就会被丢弃,等待下一次机会再显示,而这时显示

关于Vue的各个UI框架(elementUI、mint-ui、VUX)

elementUI 官网:http://element.eleme.io/ 使用步骤: 1.安装完vue-cli后,再安装 element-ui 命令行:npm i element-ui -D 相当于  npm install element-ui --save-dev //   i -> install       D  -> --save-dev       S -> --save   都是缩写 2.在main.js入口文件中引入它的js和css import ElementUI f

Vue.js之UI组件elementUI——MintUI

目的: 为了提高开发效率 功能 原则: 拿过来直接使用 vue-cli  ->  vue-loader bower 前端包管理器 jquery#1.11.1 自动解决依赖npm node包管理器 [email protected] 饿了么团队开源一个基于vue 组件库 elementUI: 如何使用 官网:http://element.eleme.io/使用:1. 安装 element-ui npm i element-ui -D npm install element-ui --save-de

第一百八十九节,jQueryUI,折叠菜单 UI

jQueryUI,折叠菜单 UI 学习要点: 1.使用 accordion 2.修改 accordion 样式 3.accordion()方法的属性 4.accordion()方法的事件 5.accordion 中使用 on 折叠菜单(accordion),和选项卡一样也是一种在同一个页面上切换不同内容的功能 UI.它和选项卡的使用几乎没有什么太大区别,只是显示的效果有所差异罢了. 一.使用 accordion 使用 accordion 比较简单,但需要按照指定的规范即可. HTML 部分 <d

学习ui设计是自学好?还是参加培训好?

ui设计自学好?还是参加培训好? 想学UI设计的人,或是想转行UI设计的人,大多都有一个困惑,要不要报班?去哪里报班?报什么班?学UI设计自学好还是报班培训好?相信这是想要进入UI设计行业领域的人们心中都有的疑问,那么该怎么办?下面小编谈谈ui设计自学好还是参加培训好的看法! 1.自学UI设计,首先是你要了解自己是有基础,还是零基础.有基础的话可以自学,不过要找到足够专业的ui学习平台,不然技术还没学会,反而把时间给耽误了,然后就是自己对学习的时间以及学习的实践操作做规划.只有持之以恒的不断学习

Winform软件,不要在线程里操作UI

对于Winform软件,不要在线程里操作UI,不要相信:StartForm.CheckForIllegalCrossThreadCalls = false; 于是,把所有的代码都改成主线程委托调用的方式 private delegate void SetTextHandle(string id, string value); private void ThreadSetText(string id, string value) { this.Controls.Find(id, true)[0].

android内存优化5—对界面UI的优化(2)

在一个应用程序中,一般都会存在多个Activity,每个Activity对应着一个UI布局文件.一般来说,为了保持不同窗口之间的风格统一,在这些UI布局文件中,几乎肯定会用到很多相同的布局.如果我们在每个xml文件中都把相同的布局都重写一遍,一个是代码冗余,可读性很差:另一个是修改起来比较麻烦,对后期的修改和维护非常不利.所以,一般情况下,我们需要把相同布局的代码单独写成一个模块,然后在用到的时候,可以通过<include /> 标签来重用layout的代码. 常见的,有的应用在最上方会有一个