IOS学习之UITableView

来源:互联网 发布:电子签名生成器软件 编辑:程序博客网 时间:2024/05/16 05:38

UITableView的常见属性

//UITableView的样式

@property (nonatomic, readonly) UITableViewStyle           style;

//UITableView的数据源

@property (nonatomic, assign)   id <UITableViewDataSource> dataSource;

//UITableView的代理

@property (nonatomic, assign)   id <UITableViewDelegate>   delegate;

//UITableView的行高

@property (nonatomic)          CGFloat                     rowHeight;

//UITAbleView每一组的头部高度

@property (nonatomic)          CGFloat                     sectionHeaderHeight;

//UITableView每一组的尾部高度

@property (nonatomic)          CGFloat                     sectionFooterHeight;

//UITableView下划线的样式

@property (nonatomic) UITableViewCellSeparatorStyle separatorStyle;

//UITableView表格的头部控件

@property (nonatomic, retain) UIView *tableHeaderView;  

//UITableView表格的底部控件

@property (nonatomic, retain) UIView *tableFooterView;   


UITableView的UITableViewDataSource数据源代理方法

//调用数据源的下面方法得知一共有多少组数据(不实现默认一组)

- (NSInteger)numberOfSectionsInTableView:(UITableView*)tableView;

//调用数据源的下面方法得知每一组有多少行数据

- (NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section;

//调用数据源的下面方法得知每一行显示什么内容

- (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath;


UITableView的UITableViewDelegate代理方法

//设置每一行的高度(如果每一行的高度不一致时使用此方法)

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;

//设置每一组头部的高度

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section;

//设置每一组尾部的高度

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section;

/**
 *  如果实现了这个方法,就自动实现了滑动删除的功能
 *  点击了删除按钮就会调用
 *  提交了一个编辑操作就会调用(操作:删除\添加)
 *  @param editingStyle 编辑的行为  UITableViewCellEditingStyleNone,    UITableViewCellEditingStyleDelete,    UITableViewCellEditingStyleInsert
 *  @param indexPath    操作的行号
 */
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath


UITableView的刷新方法

* 全局刷新(每一行都会重新刷新)
- (void)reloadData;

* 局部刷新(使用前提: 刷新前后, 模型数据的个数不变)
- (void)reloadRows:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation;

* 局部删除(使用前提: 模型数据减少的个数 == indexPaths的长度)
- (void)deleteRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation;

0 0