现在的位置: 首页 > 综合 > 正文

UITableView Class Reference

2012年10月09日 ⁄ 综合 ⁄ 共 5506字 ⁄ 字号 评论关闭

Initializing a UITableView Object //初始化UITableView对象

- (id)initWithFrame:(CGRect)frame style:(UITableViewStyle)style //通过Frame初始化

Configuring a Table View //配置Table视图

@property(nonatomic, readonly) UITableViewStyle style //Table样式(可选UITableViewStylePlain, UITableViewStyleGrouped)
- (NSInteger)numberOfRowsInSection:(NSInteger)section //返回section中的cell数量
- (NSInteger)numberOfSections //返回section的数量
@property(nonatomic) CGFloat rowHeight //列的高度,tableView:heightForRowAtIndexPath:方法与之对应
@property(nonatomic) UITableViewCellSeparatorStyle separatorStyle //分隔符的样式,在tableView:cellForRowAtIndexPath:委托方法中设置
@property(nonatomic, retain) UIColor *separatorColor //分隔符的颜色,默认为灰
@property(nonatomic, readwrite, retain) UIView *backgroundView //Table的背景

Creating Table View Cells //创建Table Cell

- (void)registerNib:(UINib *)nib forCellReuseIdentifier:(NSString *)identifier //注册一个Nib,为其添加标识符
- (void)registerClass:(Class)cellClass forCellReuseIdentifier:(NSString *)identifier //待补充
- (id)dequeueReusableCellWithIdentifier:(NSString *)identifier forIndexPath:(NSIndexPath *)indexPath //从内存池中返回指定标识符和IndexPath位置的可重用Cell,IOS6
- (id)dequeueReusableCellWithIdentifier:(NSString *)identifier //基本同上

Accessing Header and Footer Views //访问页眉和页脚

- (void)registerNib:(UINib *)nib forHeaderFooterViewReuseIdentifier:(NSString *)identifier //注册一个页眉和页脚的Nib,为其添加标识符,IOS6
- (void)registerClass:(Class)aClass forHeaderFooterViewReuseIdentifier:(NSString *)identifier //注册一个页眉页脚类,为其添加标识符,IOS6
- (id)dequeueReusableHeaderFooterViewWithIdentifier:(NSString *)identifier //通过标识符从内存池中取出一个页眉页脚 IOS6
@property(nonatomic, retain) UIView *tableHeaderView //返回一个Table Header
@property(nonatomic, retain) UIView *tableFooterView //返回一个Table Footer
@property(nonatomic) CGFloat sectionHeaderHeight //Header高度
@property(nonatomic) CGFloat sectionFooterHeight //Footer高度
- (UITableViewHeaderFooterView *)headerViewForSection:(NSInteger)section //设置指定section的Header,IOS6
- (UITableViewHeaderFooterView *)footerViewForSection:(NSInteger)section //设置指定section的Footer,IOS6

 

Accessing Cells and Sections //访问元素和块

- (UITableViewCell *)cellForRowAtIndexPath:(NSIndexPath *)indexPath //通过indexpath访问cell
- (NSIndexPath *)indexPathForCell:(UITableViewCell *)cell //通过cell查询indexpath
- (NSIndexPath *)indexPathForRowAtPoint:(CGPoint)point //通过CGPoint获取所在位置的indexPath
- (NSArray *)indexPathsForRowsInRect:(CGRect)rect //通过CGRect获取所包含Cell的indexPath数组
- (NSArray *)visibleCells //返回可见的Cell数组
- (NSArray *)indexPathsForVisibleRows //返回可见row的indexPath数组

Scrolling the Table View //滚动TableView

- (void)scrollToRowAtIndexPath:(NSIndexPath *)indexPath atScrollPosition:(UITableViewScrollPosition)scrollPosition animated:(BOOL)animated //滚动到indexPath的位置,UITableViewScrollPosition是个常量集合,表示cell在table显示区域的位置
- (void)scrollToNearestSelectedRowAtScrollPosition:(UITableViewScrollPosition)scrollPosition animated:(BOOL)animated //滚动到选中cell的位置,常量同上

Managing Selections //管理表格

- (NSIndexPath *)indexPathForSelectedRow //返回被选中的cell的indexPath
- (NSArray *)indexPathsForSelectedRows //返回被选中的cell的indexPath数组
- (void)selectRowAtIndexPath:(NSIndexPath *)indexPath animated:(BOOL)animated scrollPosition:(UITableViewScrollPosition)scrollPosition //选定指定cell并滚动到其位置
- (void)deselectRowAtIndexPath:(NSIndexPath *)indexPath animated:(BOOL)animated //取消已选中的指定cell
@property(nonatomic) BOOL allowsSelection //设置row是否可选,NO为不可选
@property(nonatomic) BOOL allowsMultipleSelection //设置是否可以多选,默认为NO
@property(nonatomic) BOOL allowsSelectionDuringEditing //设置编辑模式下是否可选,默认为NO
@property(nonatomic) BOOL allowsMultipleSelectionDuringEditing //设置编辑模式下是否可以多选,默认为NO

Inserting, Deleting, and Moving Rows and Sections //插入、删除、移动列和section

- (void)beginUpdates //在做插入、移动、删除前先调用该方法
- (void)endUpdates //操作表结束后调用该方法
- (void)insertRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation //根据指定indexPath数组插入行?
- (void)deleteRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation //根据indexPath数组删除行
- (void)moveRowAtIndexPath:(NSIndexPath *)indexPath toIndexPath:(NSIndexPath *)newIndexPath //移动指定cell到指定位置
- (void)insertSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation //插入一到多条section到指定位置
- (void)deleteSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation //删除指定section
- (void)moveSection:(NSInteger)section toSection:(NSInteger)newSection //移动section到指定位置

Managing the Editing of Table Cells //管理编辑表格元素

@property(nonatomic, getter=isEditing) BOOL editing //开启编辑模式
- (void)setEditing:(BOOL)editing animated:(BOOL)animate //开启编辑模式(与上面相同功能) 

Reloading the Table View //重载表格

- (void)reloadData //重载整个表格数据
- (void)reloadRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation //重载指定索引的数据,带动画
- (void)reloadSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation //重载指定section的数据
- (void)reloadSectionIndexTitles //重载索引栏 

Accessing Drawing Areas of the Table View //访问TableView的绘图区域

- (CGRect)rectForSection:(NSInteger)section //返回指定section的区块
- (CGRect)rectForRowAtIndexPath:(NSIndexPath *)indexPath //返回指定row的区块
- (CGRect)rectForFooterInSection:(NSInteger)section //返回指定footer的区块
- (CGRect)rectForHeaderInSection:(NSInteger)section //返回指定header的区块

Managing the Delegate and the Data Source //管理委托和数据源

@property(nonatomic, assign) id<UITableViewDataSource> dataSource //设置数据源,通常会这么用: myTableView.delegate = self; self 为viewController
@property(nonatomic, assign) id<UITableViewDelegate> delegate //设置委托,通常会这么用:     myTableView.dataSource = self; self 为viewController

Configuring the Table Index //配置表格索引(侧边那一条)

@property(nonatomic) NSInteger sectionIndexMinimumDisplayRowCount //指定当tableView中多少行的时候开始显示IndexList
@property(nonatomic, retain) UIColor *sectionIndexColor //设置索引文字颜色
@property(nonatomic, retain) UIColor *sectionIndexTrackingBackgroundColor //设置索引背景颜色

 

【上篇】
【下篇】

抱歉!评论已关闭.