IOS中UITableViewCell使用详解

IOS中UITableViewCell使用详解

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString*)reuseIdentifier;

Cell的初始化方法,可以设置一个风格和标识符,风格的枚举如下:

?


1

2

3

4

5

6

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被选中时的风格,枚举如下:

?


1

2

3

4

5

6

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的编辑状态,枚举如下

?


1

2

3

4

5

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最右侧显示的视图) 枚举如下:

?


1

2

3

4

5

6

7

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状态已经转换时调用的函数,可以在子类中重写,状态枚举如下:

?


1

2

3

4

5

typedef NS_OPTIONS(NSUInteger, UITableViewCellStateMask) {

    UITableViewCellStateDefaultMask                     = 0,//默认状态

    UITableViewCellStateShowingEditControlMask          = 1 << 0,//编辑状态

    UITableViewCellStateShowingDeleteConfirmationMask   = 1 << 1//确认删除状态

};

注意:下面这些方法已经全部在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;

设置编辑的时候是否隐藏附件视图

时间: 2024-08-07 00:12:54

IOS中UITableViewCell使用详解的相关文章

iOS 中 NSTimer 使用详解-北京尚学堂

iOS 中 NSTimer 使用详解-北京尚学堂 前阵子在整理公司项目的时候,发现老代码在使用 NSTimer 时出现了内存泄露.然后整理了一些 NSTimer 的相关内容.比较简单,各位见笑啦. NSTimer fire 我们先用 NSTimer来做个简单的计时器,每隔5秒钟在控制台输出 Fire .比较想当然的做法是这样的: @interface DetailViewController () @property (nonatomic, weak) NSTimer *timer; @end

IOS中UIActionSheet使用详解

IOS中UIActionSheet使用方法详解 一.初始化方法 - (instancetype)initWithTitle:(NSString *)title delegate:(id<UIActionSheetDelegate>)delegate cancelButtonTitle:(NSString *)cancelButtonTitle destructiveButtonTitle:(NSString *)destructiveButtonTitle otherButtonTitles:

在IOS中 NSRange类详解

NSRange的定义 typedef struct _NSRange { NSUInteger location; NSUInteger length; } NSRange; NSRange是一个结构体,其中location是一个以0为开始的index,length是表示对象的长度.他们都是NSUInteger类型. 而NSUInteger类型的定义如下: #if __LP64__ || TARGET_OS_EMBEDDED || TARGET_OS_IPHONE || TARGET_OS_WI

iOS中 断点下载详解 韩俊强的博客

布局如下: 基本拖拉属性: #import "ViewController.h" #import "AFNetworking.h" @interface ViewController () @property (weak, nonatomic) IBOutlet UILabel *progressLabel; @property (weak, nonatomic) IBOutlet UIProgressView *progressView; @property (n

IOS中的手势详解

1.点击 UITapGestureRecognizer *tap=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(click)]; //设置当前需要点击的次数 [tap setNumberOfTapsRequired:1]; //设置当前需要触发事件的手指数量 [tap setNumberOfTouchesRequired:2]; //设置当前代理 tap.delegate=self; [_view add

IOS UITableViewCell使用详解

IOS中UITableViewCell使用详解 - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier; Cell的初始化方法,可以设置一个风格和标识符,风格的枚举如下: typedef NS_ENUM(NSInteger, UITableViewCellStyle) {     UITableViewCellStyleDefault, // 默认风

动态计算UITableViewCell高度详解 (转)

感觉挺有用的一篇文章,分析了4种解决方案.回头测试之.如果有别的方案,我会在后面补上. 原文地址:http://www.ifun.cc/blog/2014/02/21/dong-tai-ji-suan-uitableviewcellgao-du-xiang-jie/ 不知道大家有没有发现,在iOS APP开发过程中,UITableView是我们显示内容常见的控件,本人觉得它是UIKit中最复杂的一个控件.今天要向大家介绍的就是如何动态计算UITableViewCell高度的一经验与技巧,在此做一

iOS UITableView代理方法详解

原 iOS UITableView代理方法详解 IOS UITableView的代理方法详解(http://my.oschina.net/u/2340880/blog/404958) 一.补充 在上一篇博客中,http://my.oschina.net/u/2340880/blog/404605,我将IOS中tableView(表视图)的一些常用方法总结了一下,这篇将tableView的代理方法作了总结,对上一篇博客进行了补充. 二.UITableViewDataSourc(数据源代理) 1.必

ios新特征 ARC详解

IOS ARC 分类: IOS ARC2013-01-17 09:16 2069人阅读 评论(0) 收藏 举报 目录(?)[+] 关闭工程的ARC(Automatic Reference Counting) 顺带附上ARC教程 本文部分实例取自iOS 5 Toturail一书中关于ARC的教程和公开内容,仅用于技术交流和讨论.请不要将本文的部分或全部内容用于商用,谢谢合作. 欢迎转载本文,但是转载请注明本文出处:http://www.onevcat.com/2012/06/arc-hand-by