UITableView 表视图

2020-04-09  本文已影响0人  邻家小哥哥

继承UIScrollView继承它所有属性

属性

UITableView *tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];

UITableViewStylePlain 基本类型
UITableViewStyleGrouped 分组类型

tableView.separatorStyle = UITableViewCellSeparatorStyleNone;//这种分离器风格是目前只支持分组样式表视图

UITableViewCellSeparatorStyleNone
UITableViewCellSeparatorStyleSingleLine
UITableViewCellSeparatorStyleSingleLineEtched

tableView.separatorInset = UIEdgeInsetsMake(0, 20, 0, 20);
tableView.separatorColor = [UIColor blackColor];
tableView.tableHeaderView = view;
tableView.tableFooterView = view;
NSArray *array = [self.rightTable indexPathsForVisibleRows];

rowHeight 行高
sectionHeaderHeight 区块头部高
sectionFooterHeight 区块尾部高
estimatedRowHeight 估计行高
estimatedSectionHeaderHeight 估计区块头部高
estimatedSectionFooterHeight 估计区块尾部高

cell.selectionStyle = UITableViewCellSelectionStyleNone;

UITableViewCellSelectionStyleBlue 蓝色
UITableViewCellSelectionStyleGray 灰色
UITableViewCellSelectionStyleDefault 默认

cell.accessoryType = UITableViewCellAccessoryNone;

UITableViewCellAccessoryDisclosureIndicator cell的右边有一个小箭头,距离右边有十几像素
UITableViewCellAccessoryDetailDisclosureButton cell右边有一个蓝色的圆形button
UITableViewCellAccessoryCheckmark cell右边的形状是对号


代理Delegate & 数据源DataSouce

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 100;
}
[tableView reloadData];
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 100;
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *reuse = @"reuseID";//复用,static-只执行一次
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuse];
if (!cell) {//如果为空,则重新创建,不为空从缓存池中获取
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuse];
    }
    return cell;
}

UITableViewCellStyleValue1 左对齐标签和蓝色标签左对齐和右对齐文本(用于设置)
UITableViewCellStyleValue2 右对齐标签剩下蓝色文本和左对齐标签(用于手机/联系人)
UITableViewCellStyleSubtitle 左对齐标签顶部和左对齐标签底部灰色文本(用于iPod)

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 100;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 100;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 100;
}
-(CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 100;
}
-(CGFloat)tableView:(UITableView *)tableView estimatedHeightForHeaderInSection:(NSInteger)section {
    return 100;
}
-(CGFloat)tableView:(UITableView *)tableView estimatedHeightForFooterInSection:(NSInteger)section {
return 100;
}
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
HeroGroup *hg = _heroAry[section];
    return hg.header;
}
-(UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    return nil;
}
-(NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section{
HeroGroup *hg = _heroAry[section];
    return hg.footer;
}
-(UIView*)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    return nil;
}
-(NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView {
    return indexs;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
}
-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath;
-(void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath;
-(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath;
-(NSIndexPath *)tableView:(UITableView *)tableView targetIndexPathForMoveFromRowAtIndexPath:(NSIndexPath *)sourceIndexPath toProposedIndexPath:(NSIndexPath *)proposedDestinationIndexPath;
-(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath;
-(BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath;
- (void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section {
}
- (void)tableView:(UITableView *)tableView willDisplayFooterView:(UIView *)view forSection:(NSInteger)section {
}
- (void)insertSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation;// 插入
- (void)deleteSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation;// 删除
- (void)reloadSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation;// 更新
- (void)moveSection:(NSInteger)section toSection:(NSInteger)newSection; //移动
上一篇 下一篇

猜你喜欢

热点阅读