基本属性
// 表单控件
UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 320, 480) style:UITableViewStylePlain];
tableView.delegate = self;
tableView.dataSource = self;
[self.view addSubview:tableView];
// 设置表单的头部视图
// tableView只有一个头视图和一个尾视图
// 但是每个section都有一个头视图和尾视图
UIImageView *headerView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 30)];
headerView.backgroundColor = [UIColor redColor];
tableView.tableHeaderView = headerView;
tableView.separatorColor = [UIColor redColor];
// 设置表单的头部视图
// tableView只有一个头视图和一个尾视图
// 但是每个section都有一个头视图和尾视图
UIImageView *headerView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 30)];
headerView.backgroundColor = [UIColor redColor];
tableView.tableHeaderView = headerView;
UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 30)];
footerView.backgroundColor = [UIColor blueColor];
tableView.tableFooterView = footerView;
——————————————————————————————————————————————————————
datasource and delegate
表单视图中有多少个section
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
——————————————————————————————————————————————————————
某一个section的row数量
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
——————————————————————————————————————————————————————
某一个section的头视图标题
- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section
——————————————————————————————————————————————————————
某一个section的尾视图标题
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
——————————————————————————————————————————————————————
用于初始化特定位置的cell
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
——————————————————————————————————————————————————————
section对应的index
Asks the data source to return the index of the section having the given title and section title index.
告诉数据源返回有给定标题和section标题的section的索引
- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index
——————————————————————————————————————————————————————
Asks the data source to commit the insertion or deletion of a specified row in the receiver.
告诉数据源来提交在特定的行插入或者删除的操作
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
——————————————————————————————————————————————————————
Tells the data source to move a row at a specific location in the table view to another location.
告诉数据源来移动一个行从一个指定的位置 到表单视图中的另一个位置
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath
——————————————————————————————————————————————————————
// 选中行操作
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
——————————————————————————————————————————————————————
// 反选行操作 - 取消选中
-(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
UITableView
最新推荐文章于 2024-06-13 14:09:53 发布