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. To making it count.

    - How do you take your caviar, sir? 鱼子酱还要吗,先生? - No caviar for me, thanks.  Never did like it much. ...

  2. Debian Security Advisory DSA-4419-1 twig security update

    Package        : twigCVE ID         : CVE-2019-9942 Fabien Potencier discovered that twig, a templat ...

  3. Python核心编程(网络编程)

    1.python socket模块内置方法 2.tcp服务器伪代码 3.tcp客户端伪代码 4.socket模块属性 5.一个简单的tcp客户端和服务端 服务端代码: # encoding:utf-8 ...

  4. 2018-2019 20165237网络对抗 Exp4 恶意代码分析

    2018-2019 20165237网络对抗 Exp4 恶意代码分析 实验目标 1.1是监控你自己系统的运行状态,看有没有可疑的程序在运行. 1.2是分析一个恶意软件,就分析Exp2或Exp3中生成后 ...

  5. LeetCode第二十四题-交换链表中节点值

    Swap Nodes in Pairs 问题简介:给定链表,交换每两个相邻节点并返回链表. 举例: 输入:1->2->3->4 输出:2->1->4->3 链表结构 ...

  6. 2018-2019-1 20165231 实现mypwd(选做)

    实现mypwd 要求: 学习pwd命令 研究pwd实现需要的系统调用(man -k; grep),写出伪代码 实现mypwd 测试mypwd pwd: 在Linux层次结构中,想要知道当前所处的目录, ...

  7. openGL learning

    1,basic env in linux : cmake_minimum_required(VERSION 2.8) project(CP_01) set(GLFW_HOME /home/gearsl ...

  8. 简单的接口测试类和测试生成报告工具HTMLTestRunner.py

    Demo.py #coding:utf-8 # import requests import json ''' data = { 'username':'jackson', 'password':'a ...

  9. Nginx动态路由的新姿势:使用Go取代lua

    导语: 在Nitro 中, 我们需要一款专业的负载均衡器. 经过一番研究之后,Mihai Todor和我使用Go构建了基于Nginx.Redis 协议的路由器解决方案,其中nginx负责所有繁重工作, ...

  10. multiwan 系统配置补充

    /etc/sysctl.conf: # Controls source route verification net.ipv4.conf.default.rp_filter = # Allows to ...