iOSUI基础07

王朝学院·作者佚名  2016-08-27
窄屏简体版  字體: 小  |  中  |  大  |  超大  

TableView

属性

// 设置每一行cell的高度@PRoperty (nonatomic)CGFloat rowHeight;// 设置每一组头部的高度@property (nonatomic)CGFloat sectionHeaderHeight;// 设置分割线颜色@property (nonatomic, retain)UIColor *separatorColor// 设置表头控件@property (nonatomic, retain)UIView *tableHeaderView;// 设置表尾控件@property (nonatomic, retain)UIView *tableFooterView;// 2.组头组尾的高self.tableView.sectionHeaderHeight =55;self.tableView.sectionFooterHeight =22;// 3.设置整个tablView的头部/尾部视图self.tableView.tableHeaderView = [[UISwitch alloc] init];self.tableView.tableFooterView = [UIButton buttonWithType:UIButtonTypeInfoDark];// 4.设置我们分割线颜色(clearColor相当于取消系统分割线)//self.tableView.separatorColor = [UIColor clearColor];// 5.设置分割线样式self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;

数据源方法//cell有多少组

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView//告诉tableView第section组有多少行

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section//告诉tableView每一行显示什么内容(tableView的每一行都是UITableViewCell)

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath//告诉tableView第section组的头部标题文字

-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section// 告诉tableView第section组的尾部标题文字

-(NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section//返回每一组的索引标题

- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView// 返回每个cell的高度

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath//删除数据

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath;//

代理方法// 只要实现了这个方法,左滑出现按钮的功能就有了(一旦左滑出现了N个按钮,tableView就进入了编辑模式, tableView.editing = YES)

-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath//左滑cell时出现什么按钮

-(NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath

{

UITableViewRowAction *action0 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"关注" handler:^(UITableViewRowAction *action,NSIndexPath *indexPath) {NSLog(@"点击了关注");// 收回左滑出现的按钮(退出编辑模式)

tableView.editing =NO;

}];

UITableViewRowAction *action1 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"删除" handler:^(UITableViewRowAction *action,NSIndexPath *indexPath) {

[self.wineArray removeObjectAtIndex:indexPath.row];

[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];

}];return @[action1, action0];

}//代理方法获取点滴选中行,行号

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;//允许编辑选中行

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath;

UITableViewCell

属性://设置cell右边的指示样式//accessoryView的优先级 > accessoryType//cell.accessoryView = [[UISwitch alloc] init];@property (nonatomic) UITableViewCellAccessoryType accessoryType;// default is UITableViewCellAccessoryNone. use to set standard type

Cell 创建

注册创建

[self.tableview registerClass:[UITableViewCell class] forCellReuseIdentifier:ID];//注册后可以直接从缓存中找创建好的UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];

非注册创建

先从缓存持中查找

UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:ID];

查不到在创建

if (nil==cell)

{

cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID];

}

 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
© 2005- 王朝網路 版權所有 導航