将一种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使用的更多相关文章

  1. iOS 中使用 XIB 自定义cell 的两种方法 以及 编译出现常见 的错误 ++++(xcode6.0之后)

    一. 注册cell 1.创建自定义cell并勾选 xib :(勾选xib就会自动生成与cell文件关联的xib) 2.在 tableViewController里注册自定义Cell (或者遵守tabl ...

  2. 创建cell的三种方式

    方式一 注册cell -> 无需为cell绑定标识符 [使用UIViewController完成!] l  1> static NSString * const ID = @"c ...

  3. iOS 中使用 XIB 自定义cell的两种方法以及编译出现常见 的错误 (xcode6.0之后)

    一. 注册cell 1.创建自定义cell并勾选 xib :(勾选xib就会自动生成与cell文件关联的xib) 2.在 tableViewController里注册自定义Cell (或者遵守tabl ...

  4. 【TensorFlow】自主实现包含全节点Cell的LSTM层 Cell

    0x00 前言 常用的LSTM,或是双向LSTM,输出的结果通常是以下两个:1) outputs,包括所有节点的hidden2) 末节点的state,包括末节点的hidden和cell大部分任务有这些 ...

  5. 去除多余的cell 和最后一行cell显示顶头底线

    去除多余cell YourTableview.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero]; 最后一行cell底线顶头显示 s ...

  6. 20Mybatis_订单商品数据模型_一对一查询——resultType和resultMap两种方式以及两种方式的总结

    上一篇文章分析了数据模型,这篇文章就给出一个需求,这个需求是一对一查询,并完成这个需求. ------------------------------------------------------- ...

  7. curl文件上传有两种方式,一种是post_fileds,一种是infile

    curl文件上传有两种方式,一种是POSTFIELDS,一种是INFILE,POSTFIELDS传递@实际地址,INFILE传递文件流句柄! );curl_setopt($ch, CURLOPT_PO ...

  8. iOS开发总结-UITableView 自定义cell和动态计算cell的高度

    UITableView cell自定义头文件:shopCell.h#import <UIKit/UIKit.h>@interface shopCell : UITableViewCell@ ...

  9. thinkphp 的两种建构模式 第一种一个单入口里面定义两个模块,前台和后台,函数控制模块必须function.php前台加载前台模块的汉书配置文件,后台加载后台模块的汉书配置文件,公共文件共用。第二种架构模式两个单入口文件,分别生成两个应用定义define。。。函数可以定义配置文件。。。。

    thinkphp 的两种建构模式  第一种一个单入口里面定义两个模块,前台和后台,函数控制模块必须function.php前台加载前台模块的汉书配置文件,后台加载后台模块的汉书配置文件,公共文件共用. ...

随机推荐

  1. VisualSVN Server提供程序无法执行所尝试的操作 0x80041024

    VisualSVN安装后没有提供VisualSVN Server Manager的快捷方式,如下图: 可以在安装目录的bin文件夹下找到VisualSVN Server.msc,添加快捷方式.建议Vi ...

  2. PHP之string之trim()函数使用

    trim (PHP 4, PHP 5, PHP 7) trim - Strip whitespace (or other characters) from the beginning and end ...

  3. Java Stream File & IO

    摘录自:http://www.runoob.com/java/java-files-io.html Java 流(Stream).文件(File)和IO Java.io包几乎包含了所有操作输入.输出需 ...

  4. laravel5.4学习--laravel基本路由

    最基本的 Laravel 路由只接收一个 URI 和一个闭包,并以此提供一个非常简单且优雅的定义路由方法: Route::get('foo', function () {return 'Hello W ...

  5. [转]Support Composite Key in ASP.NET Web API OData

    本文转自:https://code.msdn.microsoft.com/Support-Composite-Key-in-d1d53161 he default EntitySetControlle ...

  6. WebUtility(提供在处理 Web 请求时用于编码和解码 URL 的方法。)

    public static string UrlEncode( string str ) UrlEncode(String) 方法可用来编码整个 URL,包括查询字符串值. 如果没有编码情况下,如空格 ...

  7. 【转】前端——实用UI组件库

    Angular UI 组件 ngx-bootstrap 是一套Bootstrap 组件 官网:https://valor-software.com/ngx-bootstrap/#/ github: h ...

  8. SQL Serever学习14——存储过程和触发器

    存储过程 在数据库中很多查询都是大同小异,编写他们费时费力,将他们保存起来,以后执行就很方便了,把SQL语句“封装”起来. 存储过程的概念 存储过程是一组SQL语句集,经过编译存储,可以”一次编译,多 ...

  9. php中的字符串常用函数 str_replace 字符串替换,替换全角空格

    <?php $str = "hello world!"; echo(str_replace(array('hello', 'world'), array('tom', 'cl ...

  10. 怎么让一段xml被识别为字符串

    public static String decodeString(String strData) { strData = replaceString(strData, "<" ...