iOS开发 -- UITableView 完整知识点总结(一)
2014-06-11 11:59
549 查看
由于最新推出的Swift语言,因此,对于UITableView的每个API都给出了OC与Swift两种语言的声明。
本人根据苹果官方API总结了常用的属性与方法供参考。
OverView
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
本人根据苹果官方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->NSObjectObjective-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
相关文章推荐
- 学习IOS开发UI篇--UITableView中Cell的创建方式总结
- iOS开发笔记--解决UITableView中Cell重用机制导致内容出错的方法总结
- ios开发总结之UITableView常用属性和方法
- ios知识点总结——UITableView的展开与收缩及横向Table
- iOS开发总结之UITableView表格数据的批量操作2
- iOS开发笔记--解决UITableView中Cell重用机制导致内容出错的方法总结
- 学习IOS开发UI篇--UI知识点总结(二) UILabel/UIImageView
- iOS开发笔记--解决UITableView中Cell重用机制导致内容出错的方法总结
- iOS开发总结之项目开发中使用UITableView几百行代码搞定级联表格
- iOS开发 UITableView的方法和属性总结
- iOS开发之UITableView使用总结
- iOS开发——项目实战总结&UITableView性能优化与卡顿问题
- UITableView---iOS开发的常用控件使用总结
- iOS开发学习总结——UITableView使用初步
- iOS开发总结之项目开发中使用UITableView自定义多级表格&自定义cell
- iOS开发总结之UITableView表格数据的批量操作
- 【IOS 开发学习总结-OC-51】★★★ios开发之UI控件——UITableView 与UITableViewCell
- iOS开发知识点汇集四 —— UITableView的使用
- 学习IOS开发UI篇--UI知识点总结(三) UIScrollView/UIPageControl/NSTimer
- ios知识点总结——UITableView的展开与收缩及横向Table