IOS中UITableViewCell使用详解
IOS中UITableViewCell使用详解
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier;
Cell的初始化方法,可以设置一个风格和标识符,风格的枚举如下:
? typedef NS_ENUM(NSInteger, UITableViewCellStyle) {
UITableViewCellStyleDefault, // 默认风格,自带标题和一个图片视图,图片在左
UITableViewCellStyleValue1, // 只有标题和副标题 副标题在右边
UITableViewCellStyleValue2, // 只有标题和副标题,副标题在左边标题的下边
UITableViewCellStyleSubtitle // 自带图片视图和主副标题,主副标题都在左边,副标题在下
}; @property (nonatomic, readonly, retain) UIImageView *imageView;
图片视图,风格允许时才会创建
@property (nonatomic, readonly, retain) UILabel *textLabel;
标题标签 @property (nonatomic, readonly, retain) UILabel *detailTextLabel;
副标题标签 @property (nonatomic, readonly, retain) UIView *contentView;
容纳视图,任何cell的子视图都应该添加在这个上面 @property (nonatomic, retain) UIView *backgroundView;
背景视图 @property (nonatomic, retain) UIView *selectedBackgroundView;
选中状态下的背景视图 @property (nonatomic, retain) UIView *multipleSelectionBackgroundView;
多选选中时的背景视图 @property (nonatomic, readonly, copy) NSString *reuseIdentifier;
cell的标识符 - (void)prepareForReuse;
当被重用的cell将要显示时,会调用这个方法,这个方法最大的用武之地是当你自定义的cell上面有图片时,如果产生了重用,图片可能会错乱(当图片来自异步下载时及其明显),这时我们可以重写这个方法把内容抹掉。 @property (nonatomic) UITableViewCellSelectionStyle selectionStyle;
cell被选中时的风格,枚举如下:
? typedef NS_ENUM(NSInteger, UITableViewCellSelectionStyle) {
UITableViewCellSelectionStyleNone,//无
UITableViewCellSelectionStyleBlue,//蓝色
UITableViewCellSelectionStyleGray,//灰色
UITableViewCellSelectionStyleDefault//默认 为蓝色
}; @property (nonatomic, getter=isSelected) BOOL selected;
设置cell是否选中状态 @property (nonatomic, getter=isHighlighted) BOOL highlighted;
设置cell是否高亮状态 - (void)setSelected:(BOOL)selected animated:(BOOL)animated;
- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated;
与上面的两个属性对应 @property (nonatomic, readonly) UITableViewCellEditingStyle editingStyle;
获取cell的编辑状态,枚举如下
? typedef NS_ENUM(NSInteger, UITableViewCellEditingStyle) {
UITableViewCellEditingStyleNone,//无编辑
UITableViewCellEditingStyleDelete,//删除编辑
UITableViewCellEditingStyleInsert//插入编辑
}; @property (nonatomic) BOOL showsReorderControl;
设置是否显示cell自带的自动排序控件
注意:要让cell实现拖动排序的功能,除了上面设置为YES,还需实现代理中的如下方法: -(BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath{
return YES;
}
-(void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath{ } @property (nonatomic) BOOL shouldIndentWhileEditing;
设置编辑状态下是否显示缩进 @property (nonatomic) UITableViewCellAccessoryType accessoryType;
设置附件视图的风格(cell最右侧显示的视图) 枚举如下:
? typedef NS_ENUM(NSInteger, UITableViewCellAccessoryType) {
UITableViewCellAccessoryNone, // 没有视图
UITableViewCellAccessoryDisclosureIndicator, // cell右侧显示一个灰色箭头
UITableViewCellAccessoryDetailDisclosureButton, // 显示详情符号和灰色箭头
UITableViewCellAccessoryCheckmark, // cell右侧显示蓝色对号
UITableViewCellAccessoryDetailButton // cell右侧显示一个详情符号
}; @property (nonatomic, retain) UIView *accessoryView;
附件视图 @property (nonatomic) UITableViewCellAccessoryType editingAccessoryType;
cell编辑时的附件视图风格 @property (nonatomic, retain) UIView *editingAccessoryView;
cell编辑时的附件视图 @property (nonatomic) NSInteger indentationLevel;
设置内容区域的缩进级别 @property (nonatomic) CGFloat indentationWidth;
设置每个级别的缩进宽度 @property (nonatomic) UIEdgeInsets separatorInset;
设置分割线的偏移量 @property (nonatomic, getter=isEditing) BOOL editing;
- (void)setEditing:(BOOL)editing animated:(BOOL)animated;
设置是否编辑状态 @property(nonatomic, readonly) BOOL showingDeleteConfirmation;
返回是否目前正在显示删除按钮 - (void)willTransitionToState:(UITableViewCellStateMask)state;
cell状态将要转换时调用的函数,可以在子类中重写
- (void)didTransitionToState:(UITableViewCellStateMask)state;
cell状态已经转换时调用的函数,可以在子类中重写,状态枚举如下:
? typedef NS_OPTIONS(NSUInteger, UITableViewCellStateMask) {
UITableViewCellStateDefaultMask = ,//默认状态
UITableViewCellStateShowingEditControlMask = << ,//编辑状态
UITableViewCellStateShowingDeleteConfirmationMask = << //确认删除状态
}; 注意:下面这些方法已经全部在IOS3.0后被废弃了,虽然还有效果,但是会被警告 @property (nonatomic, copy) NSString *text;
设置标题 @property (nonatomic, retain) UIFont *font;
设置字体 @property (nonatomic) NSTextAlignment textAlignment;
设置对其模式 @property (nonatomic) NSLineBreakMode lineBreakMode;
设置断行模式 @property (nonatomic, retain) UIColor *textColor;
设置字体颜色 @property (nonatomic, retain) UIColor *selectedTextColor;
设置选中状态下的字体颜色 @property (nonatomic, retain) UIImage *image;
设置图片 @property (nonatomic, retain) UIImage *selectedImage;
设置选中状态时的图片 @property (nonatomic) BOOL hidesAccessoryWhenEditing;
设置编辑的时候是否隐藏附件视图
IOS中UITableViewCell使用详解的更多相关文章
- iOS中—触摸事件详解及使用
iOS中--触摸事件详解及使用 (一)初识 要想学好触摸事件,这第一部分的基础理论是必须要学会的,希望大家可以耐心看完. 1.基本概念: 触摸事件 是iOS事件中的一种事件类型,在iOS中按照事件划分 ...
- iOS中RSA加密详解
先贴出代码的地址,做个说明,因为RSA加密在iOS的代码比较少,网上开源的也很少,最多的才8个星星.使用过程中发现有错误.然后我做了修正,和另一个库进行了整合,然后将其支持CocoaPod. http ...
- 在IOS中 NSRange类详解
NSRange的定义 typedef struct _NSRange { NSUInteger location; NSUInteger length; } NSRange; NSRange是一个结构 ...
- iOS中 支付宝钱包详解/第三方支付 韩俊强的博客
每日更新关注:http://weibo.com/hanjunqiang 新浪微博! iOS开发者交流QQ群: 446310206 一.在app中成功完成支付宝支付的过程 1.申请支付宝钱包.参考网址 ...
- iOS中 断点下载详解 韩俊强的博客
布局如下: 基本拖拉属性: #import "ViewController.h" #import "AFNetworking.h" @interface Vie ...
- iOS中 百度地图详解 韩俊强的博文
需要准备工作按照下图引进类库 需要添加 添加的两个字符串为:NSLocationWhenInUseUsageDescription / NSLocationAlwaysUsageDescripti ...
- IOS中的手势详解
1.点击 UITapGestureRecognizer *tap=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selecto ...
- iOS 单元测试之XCTest详解(一)
iOS 单元测试之XCTest详解(一) http://blog.csdn.net/hello_hwc/article/details/46671053 原创blog,转载请注明出处 blog.csd ...
- iOS学习之UINavigationController详解与使用(一)添加UIBarButtonItem
http://blog.csdn.net/totogo2010/article/details/7681879 1.UINavigationController导航控制器如何使用 UINavigati ...
随机推荐
- 【转】Deep Learning(深度学习)学习笔记整理系列之(二)
因为我们要学习的是特征的表达,那么关于特征,或者说关于这个层级特征,我们需要了解地更深入点.所以在说Deep Learning之前,我们有必要再啰嗦下特征(呵呵,实际上是看到那么好的对特征的解释,不放 ...
- 1.1 、Django 后台
Django 后台 与后台相关文件:每个app中的 admin.py 文件与后台相关. 一,新建一个 名称为 HelloDjango 的项目 django-admin.py startproject ...
- placement new--《C++必知必会》 条款35
placement new是重载operator new的一个标准.全局的版本,它不能被自定义的版本代替(不像普通的operator new和operator delete能够被替换成用户自定义的版本 ...
- NodeJS学习笔记六
Symbol简介 ES6引入了一种新的原始数据类型Symbol,表示独一无二的值.它是JavaScript语言的第七种数据类型,前六种是:Undefined.Null.布尔值(Boolean).字符串 ...
- Wannafly挑战赛28 Solution
A:msc和mas Solved. 考虑斐波那契数列,即最多加45次即会超过1e9,直接暴力即可 #include <bits/stdc++.h> using namespace std; ...
- C++11多线程教学
转自:http://www.cnblogs.com/lidabo/p/3908705.html 本篇教学代码可在GitHub获得:https://github.com/sol-prog/threads ...
- bzoj1617 / P2904 [USACO08MAR]跨河River Crossing
P2904 [USACO08MAR]跨河River Crossing 显然的dp 设$f[i]$表示运走$i$头奶牛,木筏停在未过河奶牛一侧所用的最小代价 $s[i]$表示一次运$i$头奶牛到对面的代 ...
- 怎样快速掌握一个用你没学过的框架写的PHP项目?
我的思路一般是先搞定框架的route.也就是说,明白一个请求的url地址是对应的哪个controller处理的,找到controller后,再理解一下它的类库加载方案,也就是说一些辅助类以及自己逻辑类 ...
- linux及安全《Linux内核设计与实现》第四章——20135227黄晓妍
第四章 进程调度 进程调度程序是一个内核子系统 分配有限的处理器时间和资源 最大限度利用时间的原则(只要有可执行的进程,那么总会有进程执行) 基本工作:从一组处于等待(阻塞)状态的可执行进程中选择一个 ...
- 想转行学Java,却又担心自己半路出家成不了大牛
想转行学Java,却又担心自己半路出家成不了大牛 很多人看好Java编程的高薪前景,在自己职业生涯迷茫的时候,想转行学Java,却又担心自己半路出家成不了大牛,赚不到钱,本文就为大家分析一下,转行学J ...