一直觉得自己写的不是技术,而是情怀,一个个的教程是自己这一路走来的痕迹。靠专业技能的成功是最具可复制性的,希望我的这条路能让你们少走弯路,希望我能帮你们抹去知识的蒙尘,希望我能帮你们理清知识的脉络,希望未来技术之巅上有你们也有我。

下面介绍一下tableview的常用属性跟方法

常用代理

<UITableViewDelegate,UITableViewDataSource>

实例化对象跟设置宽高

self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)];

添加对象

[self.view addSubview:self.tableView];

设置代理

self.tableView.delegate = self;

设置数据源

self.tableView.dataSource = self;

设置背景颜色

self.tableView.backgroundColor = [UIColor whiteColor];

是否显示竖轴滚动条 NO:显示 YES:不显示

self.tableView.showsVerticalScrollIndicator = NO;

是否显示横轴滚动条 NO:显示 YES:不显示

self.tableView.showsHorizontalScrollIndicator = NO;

不显示cell底部线条

self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;

设置底部view

self.tableView.tableFooterView = [[UIView alloc] init];

设置cell的行高

self.tableView.rowHeight = 40;

注册cell

[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"ID"];

设置头部view

self.tableView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, CGFLOAT_MIN)];

设置底部view

self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, CGFLOAT_MIN)];

设置头部高度

self.tableView.sectionHeaderHeight = CGFLOAT_MIN;

设置底部行高度

self.tableView.sectionFooterHeight = CGFLOAT_MIN;

预估行高

self.tableView.estimatedRowHeight = 0;

预估头部高度

self.tableView.estimatedSectionHeaderHeight = 0;

预估底部行高度

self.tableView.estimatedSectionFooterHeight = 0;

设置内间距

self.tableView.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);

滚动到tableView的最底部

[self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:YES];

刷新指定的某一行

[self.tableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:0 inSection:0]] withRowAnimation:UITableViewRowAnimationFade];

刷新指定的某一行

注意这个方法执行修改某个模型的数据进行刷新列 如果删除该行不能刷新列 会蹦掉的

为解决出来刷新整个tableview抖动的问题 这个比较详细

[self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:[NSIndexPath indexPathForRow:0 inSection:0], nil] withRowAnimation:UITableViewRowAnimationNone];

刷新指定的某一列

NSIndexSet *set=[NSIndexSet indexSetWithIndex:0];
[self.tableView reloadSections:set withRowAnimation:UITableViewRowAnimationFade];

删除某一行 参考2

[self.tableView deleteRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:0 inSection:0]] withRowAnimation:UITableViewRowAnimationFade];

删除整列 后刷新

[self.tableView deleteSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationFade];

实现代理方法

#pragma mark - 分组
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{return 0;
}#pragma mark - 设置每一组的头部所展示的view
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{return [[UIView alloc] init];
}#pragma mark - 设置头部文本
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {NSString *title = [[NSString alloc] init];switch (section) {case 1:title = @"只在一以下时间段内接收比分直播推送";break;default:break;}return title;}#pragma mark - 设置组的头部的高度
- (CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{return 44;
}#pragma mark - 设置每一组的底部所展示的view
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {return [[UIView alloc] init];
}#pragma mark - 设置低部文本
- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section {NSString *title = [[NSString alloc] init];switch (section) {case 0:title = @"开启后,当我投注或关注的比赛开始,进球和结束时,会自动发送推送消息提醒我";break;default:break;}return title;}#pragma mark - 设置组的低部的高度
- (CGFloat) tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {return 50;
}#pragma mark - 设置行数
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{return 0;
}#pragma mark - 设置行的高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{return 44;
}#pragma mark - cell的内容
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ID"];if (cell == nil) {cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"ID"];}return cell;
}#pragma mark - 点击cell
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{NSLog(@"%ld",indexPath.row);
}

#pragma mark - 显示右侧 组导航

- (nullable NSArray<NSString *> *)sectionIndexTitlesForTableView:(UITableView *)tableView{//到模型中自动寻找title的值返回存到数组中return [self.carGroups valueForKeyPath:@"title"];
}

#pragma mark - 当点击右侧出现的删除按钮时触发–同时实现这个方法,就会在右侧出现删除按钮

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{//NSLog(@"commitEditingStyle");//删除对应的模型[self.heros removeObjectAtIndex:indexPath.row];//刷新//[self.tableView reloadData];//将当前行从tableVIew中移除[self.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
}

#pragma mark - 设置右侧删除按钮的显示文本

- (NSString *) tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath{return @"删除";
}

自定义TableViewCell

.h

#import <UIKit/UIKit.h>NS_ASSUME_NONNULL_BEGIN@interface TableViewCell : UITableViewCell+ (instancetype)cellWithTableView:(UITableView *)tableView;@end

.m

#import "TableViewCell.h"@interface TableViewCell ()@end@implementation TableViewCell+ (instancetype)cellWithTableView:(UITableView *)tableView {static NSString *identifier = @"k<#cell当前类型#>ID";TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];if (cell == nil) {cell = [[TableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];}return cell;
}- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{if (self=[super initWithStyle:style reuseIdentifier:reuseIdentifier]) {[self buildUI];}return self;
}- (void)buildUI{self.backgroundColor = [UIColor whiteColor];self.selectionStyle = UITableViewCellSelectionStyleNone;}@end

Xib

//2.读取指定的xib文件
UITableViewCell *cell=[[[NSBundle mainBundle] loadNibNamed:@"ID" owner:nil options:nil] lastObject];//Xib加载完毕之后执行的方法(可以自定义控件)
- (void)awakeFromNib {//调用父类方法[super awakeFromNib];}

需求

1.tableview加载数据的时候顶部出现上拉加载更多的提示语

应该这个提示语是上拉加载更多的时候才应该出现的.因为控制器第一次进来的时候tableview没有数据,商家加载更多的提示语有默认设置了,所以就会看到这段提示语.(Tap or pull up to load more)

我做NML音乐播放app的时候看到过有同时默认进来加载数据之前把tableview隐藏它.

等数据请求回来再把它显示出来.就解决了这个问题

2019年做那货商城app的时候我处理这个方法是,等tableview成功加载到数据之后才显示footerview

tableview初始化设置的时候是把footerview隐藏的

2.swift,如果加载Xib

class func showWelcomeView() -> WelcomeView {guard let view = WelcomeView.loadFromNib(named: "WelcomeView", bundle: nil) as? WelcomeView else { return WelcomeView() }view.frame = CGRect(x: 0, y: 0, width: ScreenWidth, height: ScreenHeight)view.backgroundColor = UIColor(white: 100.0/255.0, alpha: 0.75)return view}

3.如何隐藏tableviewcell的分割线

说明:分割线是系统的tablebiewcell才会有的,使用自定义cell是没有分割线的,我使用OC语言创建个Demol试过,今天去维护公司NML项目的时候发现之前的人使用自定义cell一样还会出现分割线,所以才上网查了一下隐藏分割线的方法,通过验证下面的方法是可以隐藏分割线的

处理方法

OC 基础 UITableView相关推荐

  1. OC基础回想(十二)协议

    在OC基础(十一)中我们讨论了类别和非正式协议的奇异之处.在使用非正式协议时.能够仅仅实现你想要获得响应的方法.也不必在对象中声明不论什么内容来表示该对象可用作托付对象. 全部这些任务能够用最少的代码 ...

  2. OC基础第四讲--字符串、数组、字典、集合的常用方法

    OC基础第四讲--字符串.数组.字典.集合的常用方法 字符串.数组.字典.集合有可变和不可变之分.以字符串为例,不可变字符串本身值不能改变,必须要用相应类型来接收返回值:而可变字符串调用相应地方法后, ...

  3. OC基础 代理和协议

    OC基础 代理和协议 1.协议 (1)oc语言中得协议:一组方法列表,不需要我们自己实现,由遵守协议的类来实现协议所定制的方法. (2)协议的使用步骤:制定协议-->遵守协议-->实现协议 ...

  4. OC基础1:一些基本概念

    "OC基础"这个分类的文章是我在自学Stephen G.Kochan的<Objective-C程序设计第6版>过程中的笔记. 1.关于类方法和实例方法: (1).类方法 ...

  5. OC基础15:内存管理和自动引用计数

    "OC基础"这个分类的文章是我在自学Stephen G.Kochan的<Objective-C程序设计第6版>过程中的笔记. 1.什么是ARC? (1).ARC全名为A ...

  6. oc基础 不可变字符串的创建和使用

    oc基础  不可变字符串的创建和使用 简介:下面都是字符串基本用法. 1.字符串的创建 //创建oc常量字符串NSString *str=@"hello world!";NSLog ...

  7. iOS开发面试知识整理 – OC基础 (二)

    iOS | 面试知识整理 – OC基础 (二) 1.C和 OC 如何混编 xcode可以识别一下几种扩展名文件: .m文件,可以编写 OC语言 和 C 语言代码 .cpp: 只能识别C++ 或者C语言 ...

  8. OC基础学习 调用方式

    OC基础学习 调用方式 调用方法: C++里,送一个消息给对象(或者说调用一个方法)的语法如下: obj.method(argument); Objective-C则写成: [obj method: ...

  9. iOS战记 ----OC基础语法之战(一)

    iOS战记  ----OC基础语法之战(一) 一个机械设计者的转行之战. 火车一个年轻的程序员和一个项目经理登上了一列在山里行驶的火车,他们发现列车上几乎都坐满了,只有两个在一起的空位,这个空位的对面 ...

最新文章

  1. 清华大学教授:唐杰——深度分析:人工智能的下个十年
  2. 14 款免费漂亮的 BuddyPress 主题
  3. 手把手带你写一个JavaScript类型判断小工具
  4. Javascript中的内置对象:RegExp对象
  5. 【matplotlib笔记】sin图像与cos图像
  6. 吴伯凡-认知方法论-为什么说“盲维”是认知升级的重要概念
  7. 安卓 VNET 抓取 wskey 教程
  8. love2d贪吃蛇---画方格
  9. ei会议论文含金量高吗?
  10. 从零开始的VUE项目-03(数据的增删改查)
  11. 开源电子书项目FBReader初探(六)
  12. 【阿里巴巴】学习Java在面试过程中跳槽成功的心得总结
  13. js实现图片无缝滚动特效
  14. 创成汇:利用所学为国家医疗领域尽自己的一份力!海归的创业路_
  15. 《点石成金》 思维导图
  16. 【图片、视频修复】Real-CUGAN的简单使用
  17. zabbix php ldap off,安装zabbix时PHP ldap Warning解决方法
  18. 史上最全的整数分解方法(包含经典的分苹果问题)
  19. std::string 含义
  20. LeetCode(Python)—— 加一(简单)

热门文章

  1. win10 家庭版如何能远程桌面控制
  2. 小平方水果店怎么摆放,水果店陈列怎么比较好
  3. CocoaPods 【CocoaPods 全攻略】
  4. CocoaPods——Cocoapods 入门
  5. C++-二叉树递归遍历与非递归遍历实现
  6. 【代码分解】用Python实现一个电影订票系统
  7. 第一章Python概述
  8. 深度学习大牛andrew.Ng DeepLearning
  9. 基于JAVA高校共享机房管理系统的设计与实现计算机毕业设计源码+系统+数据库+lw文档+部署
  10. 【Python成长之路】制作口令保险箱GUI版