您的位置:首页 > 产品设计 > UI/UE

iOS开发 -- UITableView 完整知识点总结(一)

2014-06-11 11:59 549 查看
由于最新推出的Swift语言,因此,对于UITableView的每个API都给出了OC与Swift两种语言的声明。

本人根据苹果官方API总结了常用的属性与方法供参考。

OverView


/*An instance of
UITableView (or simply, a table view) is a means for displaying and editing hierarchical lists of information*/
一个UITableView的实例是一个用于展示和编辑层次化列表结构的工具.

Tasks

1.初始化一个UITableView对象

首先,理清继承关系 UITableView->UIScrollView->UIView->UIResponder->NSObject
Objective-C

- (instancetype)initWithFrame:(CGRect)frame

style:(UITableViewStyle)style
其中UITableViewStyle这个枚举
typedef enum
{
UITableViewStylePlain,
UITableViewStyleGrouped
}
UITableViewStyle;
默认情况下为UITableViewStylePlain
通过这个实例方法,我们可以创建出一个分组或者扁平的tableview出来
Swift

init(frameframe:

CGRect,

style style:UITableViewStyle)
其中UITableViewStyle枚举类型为

enum UITableViewStyle :

Int {
case Plain
case Grouped
}
2.配置一个UITableView
一般一个UITableView的常用属性有9个,分别为:
(1)style /*Returns the style of the receiver. (read-only)*/ /*样式(只读)*/

Objective-C
@property(nonatomic,readonly)
UITableViewStylestyle
Swift

var style:
UITableViewStyle { get }
(2)numberOfRowsInSection /*一个section的行数*/
Objective-C

- (NSInteger)numberOfRowsInSection:(NSInteger)section
Swift

func
numberOfRowsInSection(_section:

Int) -> Int
(3)numberOfSections /*section的个数*/
Objective-C

- (NSInteger)numberOfSections

(4)rowHeight /*每一个UITableViewCell的行高*/
Objective-C

@property(nonatomic)CGFloat
rowHeight
Swift

var rowHeight:
CGFloat
对于这个属性,如果代理没有实现
tableView:heightForRowAtIndexPath:方法,你就必须设置cell的行高。
如果你不显示的设置它,tableview会自动设置其为一个标准值,通常为44
(5)separatorStyle /*每个UITableViewCell之间分割线的样式*/
Objective-C

@property(nonatomic)UITableViewCellSeparatorStyle
separatorStyle
其中UITableViewCellSeparatorStyle枚举类型:

typedef enum
:NSInteger
{
UITableViewCellSeparatorStyleNone,
UITableViewCellSeparatorStyleSingleLine,
UITableViewCellSeparatorStyleSingleLineEtched
}
UITableViewCellSeparatorStyle;
Swift

var separatorStyle:

UITableViewCellSeparatorStyle
其中UITableViewCellSeparatorStyle枚举类型:

enum UITableViewCellSeparatorStyle :

Int {
case None
case SingleLine
case SingleLineEtched
}
(6)separatorColor /*每个UITableViewCell之间分割线的颜色*/
Objective-C

@property(nonatomic,retain)

UIColor *separatorColor
Swift

var separatorColor:
UIColor!
PS:
关于Swift中的!与?的具体解释

(7)separatorEffect /*The effect applied to table separators.*/ /*应用到分割线的效果*/
Objective-C

@property(nonatomic,copy)

UIVisualEffect *separatorEffect
PS:该属性为iOS8.0 最新API
Swift

var separatorEffect:

UIVisualEffect!
(8)backgroundView /*The background view of the table view.*/ /*table view的背景view*/
Objective-C

@property(nonatomic,readwrite,
retain)UIView
*backgroundView
Swift

var backgroundView:

UIView!
PS:
/*A table view’s background view is automatically resized to match the size of the table view. This view is placed as a subview of the table view behind all cells , header views, and footer views.
You must set this property to
nil to set the background color of the table view.*/
大意就是说一个backgroundView是自动的去适配tableView的大小的,而且这个view是被放置在所有cell,头部view和底部view的后面.如果要设置tableView的背景色的话,需要将该属性设置为nil.
(9)separatorInset /*Specifies the default inset of cell separators.*/ /*指定cell分割线的inset*/
Objective-C

@property(nonatomic)UIEdgeInsets
separatorInset
Swift

var separatorInset:

UIEdgeInsets
PS:
/*Only left and right insets are honored.*/ /*只有左侧和右侧的insets起作用?(英语捉急。。)*/
该属性也是iOS7以上的API
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: