UITableView 

//UIViewController里添加一个UITableView
@interface ViewController : UIViewController<UITableViewDelegate,UITableViewDataSource> @property (nonatomic, strong) UITableView * tableView; @end //初始化,当然还有其他初始方法,不赘述了
_tableView = [[UITableView alloc] init];
//设置代理
_tableView.delegate = self;
_tableView.dataSource = self;
//界面添加
[self.view addSubview:_tableView];
//设置尺寸,当然也可以通过masonry之类的添加约束
[_tableView setFrame:self.view.frame];
//各种属性设置
//分割线(无分割线)
_tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
//背景颜色
_tableView.backgroundColor = [UIColor WhiteColor];
//section数目
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return ;
} //每个section有几个单元格
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return ;
}
///////////////////////////////////
//单元格具体实现
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
//注意单元格的复用
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
if (!cell)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
}
return cell;
}
//单元格高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return ;
}
//点击单元格触发的事件
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"你点了一个cell");
}
//////////////////////////////////////// //section头部的具体实现
- (nullable UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
return [[UIView alloc] init];
}
//section头部高度
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return ;
}
//section footer的具体实现
- (nullable UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
return [[UIView alloc] init];
}
//section footer 高度
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
return ;
}
// 设置 cell 是否允许左滑
-(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
return true;
}
// 设置默认的左滑按钮的title
-(NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath {
return @"按钮钮钮";
}
// 点击左滑出现的按钮时触发
-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@"点击左滑出现的按钮时触发");
}
// 左滑结束时调用(只对默认的左滑按钮有效,自定义按钮时这个方法无效)
-(void)tableView:(UITableView *)tableView didEndEditingRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@"左滑结束");
}

新建的UITableViewCell中加入这一句作为cell的初始化函数

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
//在这里写入定制cell的内容
}
return self;
}

[OC] UITableView 与 UItableViewCell 的使用的更多相关文章

  1. UITableView和UITableViewCell的几种样式

    UITableView和UITableViewCell的几种样式 转至  http://blog.csdn.net/crazyzhang1990/article/details/12503163 一. ...

  2. 03 (OC)* UITableView优化

    一:cell注册和初始化 1:不注册cell 2:注册类 3:注册nib 4:storyboard 二:核心思想 1:UITableView的核心思想是:cell的重用机制.UITbleView只会创 ...

  3. UITableView与UITableViewCell

    转自:http://blog.sina.com.cn/s/blog_4cd14afb01014j97.html UITableView用来以表格的形式显示数据.关于UITableView,我们应该注意 ...

  4. iOS 初学UITableView、UITableViewCell、Xib

    注意事项: 1.一个.xib里面最多设置一个cell 2.要仔细调整自动布局,其实它不太好用 3.记得设置<UITableViewDataSource>委托 4.记得在ViewContro ...

  5. UI第十八节——UITableView

    在iOS开发中UITableView可以说是使用最广泛的控件,我们平时使用的软件中到处都可以看到它的影子,基本大部分应用都有UITableView.当然它的广泛使用自然离不开它强大的功能,今天就针对U ...

  6. iOS开发系列--UITableView全面解析

    --UIKit之UITableView 概述 在iOS开发中UITableView可以说是使用最广泛的控件,我们平时使用的软件中到处都可以看到它的影子,类似于微信.QQ.新浪微博等软件基本上随处都是U ...

  7. UITableView或UIScrollVIew上的UIButton的高亮效果

    UITableView或UIScrollVIew上的UIButton的高亮效果 原文地址:http://www.jianshu.com/p/b4331f06bd34 最近做项目的时候发现,UIScro ...

  8. 去掉UITableView多余的空白行分割线

    一.问题描述 在学习和开发中经常会遇到下面的问题,UITableView的UITableViewCell很少或者没有时,但UITableView有很多的空白行分割线.如下图: 如何去掉UITableV ...

  9. 我收录整理的优秀OC技术类文章

        自定义导航按钮UIBarButtonItem   关于导航栏的六个小技巧   ios开发的一些小技巧篇一 制作一个可以滑动操作的 Table View Cell - IOS - 伯乐在线 一个 ...

随机推荐

  1. Spring cloud gateway

    ==================================为什么需要API gateway?==================================企业后台微服务互联互通, 因为 ...

  2. django-个人博客登录及权限验证功能的实现

    完成注册后随即开始进行登录,登录后页面显示登录者的名称 实现如下: 前端页面html,对session进行判断,有值则显示登录者的名字 ,无值则显示注册字样: 后台views函数  首先对验证码进行验 ...

  3. Linux的快捷键一

  4. 移动端雪碧图sprite的实现

    移动端适配的时候,通常是用rem作为长宽单位,因此,在不同的设备下,元素的实际宽高(px)是不一样的,如果是单张图片作为为背景图片的时候,最为方便,只要设置背景图片的属性background-size ...

  5. 002 requests的使用方法以及xpath和beautifulsoup4提取数据

    1.直接使用url,没用headers的请求 import requests url = 'http://www.baidu.com' # requests请求用get方法 response = re ...

  6. important覆盖行内样式

    优先级,外部样式<内部样式<行内样式,后台富文本编辑器编辑的正文显示在前台时可用!important覆盖其行内样式 今天的问题,font-family:"思源黑体 CN!impo ...

  7. [转载]在termux上安装Kali Linux

    最近在手机上下了个Termux,然后想装个kali,就找到了这篇文章. 不过其中的命令有一处错误(在我进行配置的时候报错了): 命令应该是 ./atilo install kali

  8. opcourse sql布尔盲注 WP复现

    当时做这题的时候,写了脚本,用的if(mid())<>来爆破的,可能因为写脚本不擅长,写的太乱了,直接把payload写进mid里,整个一堆,然后括号对着WP看的时候,少了好几个括号,导致 ...

  9. Date——js 获取当前日期到之后一个月30天的日期区间

    var dateList = []; let startDate = new Date(); let endDate = new Date(); endDate.setDate(startDate.g ...

  10. 05mycat父子表

    表连接的难题在mycat中是不允许跨分片做表连接查询的 创建t_orders表 create table t_orders( id int PRIMARY key, customer_id int n ...