UITableVIew

UITableViewCell叠加 (clipsToBounds)UricRecord6Cell

image.png

如何从UITableViewCell获取UITableView

if([self.superview isKindOfClass:UITableView.class]){
                    UITableView *tableView = (UITableView*)self.superview;
                    [tableView reloadData];
                }

UITableViewCell嵌套UICollectionView自适应高度
https://www.jianshu.com/p/4bdd9e87504a

空cell,高度为0时

if(indexPath.row == 1 && [MJManager getUMIState:self.model] != 2){
                UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:(UITableViewCellStyleValue1) reuseIdentifier:@"cell"];
                return cell;
            }

初始化


@property (nonatomic, strong) UITableView *tbvData;
- (UITableView *)tbvData
{
    if (!_tbvData)
    {
        UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
        tableView.delegate = self;
        tableView.dataSource = self;
        tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        tableView.backgroundColor = kBgColor;
        [tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
        _tbvData = tableView;
    }
    return _tbvData;
}

 [self.view addSubview:self.tbvData];
 [self.tbvData mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.view);
 }];

UITableViewDelegate,UITableViewDataSource

自定义cell,分区头部,尾部

IB
UINib *cellNib = [UINib nibWithNibName:@"MineSimpleTitleTbvCell" bundle:nil];
[tableView registerNib:cellNib forCellReuseIdentifier:@"MineSimpleTitleTbvCell"];
UINib *sectionHeadNib = [UINib nibWithNibName:@"MyCustomersChildTbvHeadView" bundle:nil];
[tableView registerNib:sectionHeadNib forHeaderFooterViewReuseIdentifier:@"MyCustomersChildTbvHeadView"];

代码
[tableView registerClass:[YZGTableVIewCell class] forCellReuseIdentifier:@"YZGTableVIewCell"];
[tableView registerClass:[YZGSectionHeadView class] forHeaderFooterViewReuseIdentifier:@"YZGSectionHeadView"];


下拉刷新

_tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
    
 }];
_tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{

}];

_tableView.mj_footer.hidden = YES;
[__weakSelf.tableView.mj_header endRefreshing];
[__weakSelf.tableView.mj_footer endRefreshingWithNoMoreData];//设置没有更多数据

UITableViewDelegate,UITableViewDataSource

表头,表尾

@property (nonatomic, strong) MJTableHeadView *tbvHeadView;
@property (nonatomic, strong) MJTableFootView *tbvFootView;

IB
- (AddWeiXinTbvFootView *)tbvFootView {
    if (!_tbvFootView) {
        _tbvFootView = (AddWeiXinTbvFootView *)[NSBundle.mainBundle loadNibNamed:@"AddWeiXinTbvFootView" owner:self options:nil].lastObject;
        _tbvFootView.frame = CGRectMake(0, 0, SCREEN_WIDTH, 130);
        _tbvFootView.autoresizingMask = UIViewAutoresizingNone;
    }
    return _tbvFootView;
}
- (MyBalanceTbvHeadView *)tbvHeadView {
    if (!_tbvHeadView) {
        _tbvHeadView = (MyBalanceTbvHeadView *)[NSBundle.mainBundle loadNibNamed:@"MyBalanceTbvHeadView" owner:self options:nil].lastObject;
        _tbvHeadView.frame = CGRectMake(0, 0, SCREEN_WIDTH, AUTO_MATE_WIDTH(200));
        _tbvHeadView.autoresizingMask = UIViewAutoresizingNone;
    }
    return _tbvHeadView;
}

代码 
- (MJTableFootView *)tbvFootView {
    if (!_tbvFootView) {
        _tbvFootView = [[MJTableFootView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 200)];
    }
    return _tbvFootView;
}
- (MJTableHeadView *)tbvHeadView {
    if (!_tbvHeadView) {
        _tbvHeadView = [[MJTableHeadView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 200)];
    }
    return _tbvHeadView;
}

tableView.tableHeaderView = self.tbvHeadView;
tableView.tableFooterView = self.tbvFootView;

常用代理方法

#pragma mark ************** UITableView 代理方法
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return  _dataArray.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 50;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    static NSString *cellIden = @"cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIden];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:(UITableViewCellStyleValue1) reuseIdentifier:cellIden];
    }
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;//右边尖括号
    cell.textLabel.text = [NSString stringWithFormat:@"%ld",indexPath.row];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;//去掉点击效果
    return cell;
    
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(self.cellClickBlack)
    {
        self.cellClickBlack(_dataArray[indexPath.row]);
    }
}

分区头部,尾部

/*分区头部部高度*/
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 50;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    
    YZGSectionHeadView *sectionHeadView = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"YZGSectionHeadView"];
 
    return sectionHeadView;
    
}

/*分区尾部高度*/
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 100;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    
    YZGSectionFootView *sectionFootView = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"YZGSectionFootView"];
    return sectionFootView;
}

UITableView 方法,特性

##默认选中第一行
NSIndexPath * path = [NSIndexPath indexPathForItem:0 inSection:0];
[self tableView:self.tbvData didSelectRowAtIndexPath:path];

##一句话去除UITableView底部多余行及分割线
 tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
##取消分割线
tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
##分割线颜色
tableView.separatorColor = [UIColor redColor];
##右边尖括号
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
##去掉点击效果
cell.selectionStyle = UITableViewCellSelectionStyleNone;
##一个section刷新
NSIndexSet *indexSet=[[NSIndexSet alloc]initWithIndex:2];
[self.tbvData reloadSections:indexSet withRowAnimation:UITableViewRowAnimationAutomatic];
##一个cell刷新
NSIndexPath *indexPath=[NSIndexPath indexPathForRow:3 inSection:0];
[self.tbvData reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath,nil] withRowAnimation:UITableViewRowAnimationNone];

##滚动到指定位置  
 NSIndexPath * dayOne = [NSIndexPath indexPathForRow:0 inSection:2];  
[self.tbvData scrollToRowAtIndexPath:dayOne atScrollPosition:UITableViewScrollPositionTop animated:YES]; 
##滚动到顶部
 [self.tableView setContentOffset:CGPointMake(0,0) animated:NO];
##cell 底部留空白
- (void)setFrame:(CGRect)frame
{
    frame.size.height -= 10;
    [super setFrame:frame];
}
##cell 数据少,直接 ,不需要复用
UITableViewCell *cell = [UITableViewCell alloc]init]
##iOS 11 设配  滑动卡顿(漂移和抽疯的现象)3句不少
tableView.estimatedRowHeight = 0;
tableView.estimatedSectionHeaderHeight = 0;
tableView.estimatedSectionFooterHeight = 0;

##点击松开灰色取消
[tableView deselectRowAtIndexPath:indexPath animated:true];

##取消向下偏移 64/20
if (@available(iOS 11.0, *)) {
        self.tbvData.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    }else {
        self.automaticallyAdjustsScrollViewInsets = NO;
    }
##禁止滑动
tableView.scrollEnabled = NO;

##分割线边距
tableView.separatorInset= UIEdgeInsetsMake(0,55, 0, 0);

##tableHeadView 用xib 时候用,高度会出错
 tableView.autoresizingMask = UIViewAutoresizingNone;

##注意cell 约束的内边距
tableView.contentInset = UIEdgeInsetsMake(0, 0, 15, 0);
## sectionView 有默认颜色,xib 不修改他的 颜色,添加一个view
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    
    UIView *sectionHeadView = [[UIView alloc]init];
    sectionHeadView.backgroundColor = tableView.backgroundColor;
    return sectionHeadView;
}
#点击颜色修改
cell.selectedBackgroundView=[[UIView alloc]initWithFrame:cell.frame];
cell.selectedBackgroundView.backgroundColor= kBgColor;
#刷新后置顶
if(self.pageNumber == 1 && self.dataArray.count > 0){
        NSIndexPath * indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
        [self.tbvData scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionNone animated:NO];
    }
#TableViewCell 存UITableView 并自动计算高度
Outpatient 文件夹
F38E51B3-C589-4048-8B6C-328CBF5CCEC9.png

遇到的一些坑

###UITableView列表reloadSections等刷新数据时屏幕跳动
[UIView performWithoutAnimation:^{
        NSIndexSet *reloadSet = [NSIndexSet indexSetWithIndex:1];
        [self.workTable reloadSections:reloadSet withRowAnimation:UITableViewRowAnimationNone];
}];
————————————————
版权声明:本文为CSDN博主「番薯大佬」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/potato512/article/details/81047441
###隐藏某个cell 时候,高度为0时候,可能出现约束冲突,切换普通cell
UITableViewCellStyleValue1 搜索
###UITableViewStyleGroup 的 heightForFooterInSection 默认都是 22
设置 分区 头尾 为 0 无效
设置UITableViewStyleGroup 时候,要让分区尾部为0
(重要*************这里有一个小小的技巧,我们设置 0.01 的时候,这个时候对UITableVIew是有作用的,*****不能设置为0,不然没有效果,);

###button 添加在 cell 上,当button 设置不可点击时,点击button 时会触发cell 的点击事件,
现在让button 不可点击转态,点击button 不会触发cell 的点击事件
(可以给 让button 添加在 cell 的 一个 bottomVIew 上,给父视图添加一个空的手势点击事件,阻止事件chuan'd)

设置tableView右侧索引
https://www.jianshu.com/p/2b87b09488e6
UITableview 添加索引后整体内容左移
https://www.jianshu.com/p/8a46869b18b2
tableViewCell里嵌套collectionView
http://www.hangge.com/blog/cache/detail_1591.html
https://www.jianshu.com/p/b907c198473d
UITableView自动计算cell高度
https://github.com/forkingdog/UITableView-FDTemplateLayoutCell
https://www.jianshu.com/p/64f0e1557562
https://www.jianshu.com/p/af4bc69839d8
UITableView嵌套 UIScrollView
https://www.jianshu.com/p/8bf6c2953da3
UITableView 优化
https://blog.csdn.net/hmh007/article/details/54907560
UITableView 左滑删除
https://www.jianshu.com/p/2f37d553edb0
tableViewCell图片点击放大缩小回原位
https://blog.csdn.net/hero_wqb/article/details/50909765
TableViewCell注册和不注册复用的问题
https://www.jianshu.com/p/12beb11ae63a
UITableViewcell分割线相关、隐藏某条分割线
https://blog.csdn.net/ZHFDBK/article/details/79411351
解决iOS UITableView分组header悬浮,每个section header上面有一段空白间距
https://blog.csdn.net/smile82475/article/details/125187582

UITableView 的总结

http://www.jianshu.com/p/a5f6c534695e
http://www.jianshu.com/p/344ffc33a435
http://www.jianshu.com/p/481da2f1bf7a
http://www.jianshu.com/p/7e6b5c6c6913

拓展

willDisplayCell 和cellForRowAtIndexPath区别

UITableViewCell 嵌套 UICollectionView
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 217,657评论 6 505
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 92,889评论 3 394
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 164,057评论 0 354
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 58,509评论 1 293
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 67,562评论 6 392
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,443评论 1 302
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,251评论 3 418
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 39,129评论 0 276
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,561评论 1 314
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,779评论 3 335
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,902评论 1 348
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,621评论 5 345
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,220评论 3 328
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,838评论 0 22
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,971评论 1 269
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 48,025评论 2 370
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,843评论 2 354

推荐阅读更多精彩内容