将一种cell当做几种cell使用
将一种cell当做几种cell使用

将一种cell当做几种cell用是有着一些意义的,比如,有时候,不同的cell之间差异很小,如果再派生一个cell出来,就会显得很麻烦,这时候,将这个cell当做几个cell用才有市场的说:)
效果:



源码:
ModelCell.h 与 ModelCell.m
//
// ModelCell.h
// Cells
//
// Copyright (c) 2014年 Y.X. All rights reserved.
// #import <UIKit/UIKit.h> @interface ModelCell : UITableViewCell @property (nonatomic, assign) BOOL show1;
@property (nonatomic, assign) BOOL show2;
@property (nonatomic, assign) BOOL show3; @end
RootViewController.m
//
// RootViewController.m
// Cells
//
// Copyright (c) 2014年 Y.X. All rights reserved.
// #import "RootViewController.h"
#import "ModelCell.h" @interface RootViewController ()<UITableViewDataSource, UITableViewDelegate> @property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSArray *dataSource; @end @implementation RootViewController - (void)viewDidLoad
{
[super viewDidLoad]; // tableView
_tableView = [[UITableView alloc] initWithFrame:self.view.bounds
style:UITableViewStylePlain];
_tableView.dataSource = self;
_tableView.delegate = self;
_tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
[self.view addSubview:_tableView];
} #pragma mark - UITableView's dataSource & delegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return ;
} - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *reusedFlag = @"YouXianMing";
ModelCell *cell = [tableView dequeueReusableCellWithIdentifier:reusedFlag];
if (cell == nil) {
cell = [[ModelCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:reusedFlag];
} cell.show1 = YES;
cell.show2 = YES;
cell.show3 = YES; return cell;
} - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return .f;
} @end
核心的地方:
根据属性的setter方法动态隐藏cell中的某些控件

然后在配置cell的时候动态设定要显示的控件

just so easy :)
将一种cell当做几种cell使用的更多相关文章
- iOS 中使用 XIB 自定义cell 的两种方法 以及 编译出现常见 的错误 ++++(xcode6.0之后)
一. 注册cell 1.创建自定义cell并勾选 xib :(勾选xib就会自动生成与cell文件关联的xib) 2.在 tableViewController里注册自定义Cell (或者遵守tabl ...
- 创建cell的三种方式
方式一 注册cell -> 无需为cell绑定标识符 [使用UIViewController完成!] l 1> static NSString * const ID = @"c ...
- iOS 中使用 XIB 自定义cell的两种方法以及编译出现常见 的错误 (xcode6.0之后)
一. 注册cell 1.创建自定义cell并勾选 xib :(勾选xib就会自动生成与cell文件关联的xib) 2.在 tableViewController里注册自定义Cell (或者遵守tabl ...
- 【TensorFlow】自主实现包含全节点Cell的LSTM层 Cell
0x00 前言 常用的LSTM,或是双向LSTM,输出的结果通常是以下两个:1) outputs,包括所有节点的hidden2) 末节点的state,包括末节点的hidden和cell大部分任务有这些 ...
- 去除多余的cell 和最后一行cell显示顶头底线
去除多余cell YourTableview.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero]; 最后一行cell底线顶头显示 s ...
- 20Mybatis_订单商品数据模型_一对一查询——resultType和resultMap两种方式以及两种方式的总结
上一篇文章分析了数据模型,这篇文章就给出一个需求,这个需求是一对一查询,并完成这个需求. ------------------------------------------------------- ...
- curl文件上传有两种方式,一种是post_fileds,一种是infile
curl文件上传有两种方式,一种是POSTFIELDS,一种是INFILE,POSTFIELDS传递@实际地址,INFILE传递文件流句柄! );curl_setopt($ch, CURLOPT_PO ...
- iOS开发总结-UITableView 自定义cell和动态计算cell的高度
UITableView cell自定义头文件:shopCell.h#import <UIKit/UIKit.h>@interface shopCell : UITableViewCell@ ...
- thinkphp 的两种建构模式 第一种一个单入口里面定义两个模块,前台和后台,函数控制模块必须function.php前台加载前台模块的汉书配置文件,后台加载后台模块的汉书配置文件,公共文件共用。第二种架构模式两个单入口文件,分别生成两个应用定义define。。。函数可以定义配置文件。。。。
thinkphp 的两种建构模式 第一种一个单入口里面定义两个模块,前台和后台,函数控制模块必须function.php前台加载前台模块的汉书配置文件,后台加载后台模块的汉书配置文件,公共文件共用. ...
随机推荐
- Chapter 6. Names
6.2. Names and Identifiers A name is used to refer to an entity declared in a program. There are two ...
- css3基础下
box-shadow:0 5px 5px rgba(0,0,0,0.5) 文本 text-shadow:5px 5px 4px green; word-wrap: 背景: background:#ff ...
- python跳出多重循环
# -*- coding=utf-8 -*- """ 如何结束多重循环,在单层循环中,可以用break跳出循环,那两层,三层呢? """ # ...
- 【angular5项目积累总结】消息订阅服务
code import { Injectable } from '@angular/core'; import { Subject } from 'rxjs/Subject'; @Injectable ...
- Angular2-给属性做双向绑定
呈现一个实体对象的DOM结构,这个DOM有个自定义属性是需要动态赋值的,比如说 item.data 要绑到自定义属性 data 上:你可能会这么写: data="{{item.data}}& ...
- [转] SQL函数说明大全
from http://www.cnblogs.com/moss_tan_jun/archive/2010/08/23/1806861.html 一旦成功地从表中检索出数据,就需要进一步操纵这些数据, ...
- [javaSE] 数据结构(二叉查找树-插入节点)
二叉查找树(Binary Search Tree),又被称为二叉搜索树,它是特殊的二叉树,左子树的节点值小于右子树的节点值. 定义二叉查找树 定义二叉树BSTree,它保护了二叉树的根节点BSTNod ...
- [javaSE] IO流(管道流)
之前我们使用io流,都是需要一个中间数组,管道流可以直接输入流对接输出流,一般和多线程配合使用,当读取流中没数据时会阻塞当前的线程,对其他线程没有影响 定义一个类Read实现Runable接口,实现r ...
- 使用 NamedScope 扩展 Ninject 的 InRequestScope
背景 C#,Ninject,定期执行某计划任务.首先想到的是使用 Quartz 来安排计划任务,于是看是否有相应的集成.果然有:https://github.com/dtinteractive/Nin ...
- 【Chromium】sandboxed window问题记录
问题发现 在业务逻辑中发现有时使用chrome.app.window.create这个API创建出来的窗口无法使用其他的API,不仅其他chrome.app.window的API说window is ...