[OC] UITableView 与 UItableViewCell 的使用
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 的使用的更多相关文章
- UITableView和UITableViewCell的几种样式
UITableView和UITableViewCell的几种样式 转至 http://blog.csdn.net/crazyzhang1990/article/details/12503163 一. ...
- 03 (OC)* UITableView优化
一:cell注册和初始化 1:不注册cell 2:注册类 3:注册nib 4:storyboard 二:核心思想 1:UITableView的核心思想是:cell的重用机制.UITbleView只会创 ...
- UITableView与UITableViewCell
转自:http://blog.sina.com.cn/s/blog_4cd14afb01014j97.html UITableView用来以表格的形式显示数据.关于UITableView,我们应该注意 ...
- iOS 初学UITableView、UITableViewCell、Xib
注意事项: 1.一个.xib里面最多设置一个cell 2.要仔细调整自动布局,其实它不太好用 3.记得设置<UITableViewDataSource>委托 4.记得在ViewContro ...
- UI第十八节——UITableView
在iOS开发中UITableView可以说是使用最广泛的控件,我们平时使用的软件中到处都可以看到它的影子,基本大部分应用都有UITableView.当然它的广泛使用自然离不开它强大的功能,今天就针对U ...
- iOS开发系列--UITableView全面解析
--UIKit之UITableView 概述 在iOS开发中UITableView可以说是使用最广泛的控件,我们平时使用的软件中到处都可以看到它的影子,类似于微信.QQ.新浪微博等软件基本上随处都是U ...
- UITableView或UIScrollVIew上的UIButton的高亮效果
UITableView或UIScrollVIew上的UIButton的高亮效果 原文地址:http://www.jianshu.com/p/b4331f06bd34 最近做项目的时候发现,UIScro ...
- 去掉UITableView多余的空白行分割线
一.问题描述 在学习和开发中经常会遇到下面的问题,UITableView的UITableViewCell很少或者没有时,但UITableView有很多的空白行分割线.如下图: 如何去掉UITableV ...
- 我收录整理的优秀OC技术类文章
自定义导航按钮UIBarButtonItem 关于导航栏的六个小技巧 ios开发的一些小技巧篇一 制作一个可以滑动操作的 Table View Cell - IOS - 伯乐在线 一个 ...
随机推荐
- js 时间格式化 兼容safari 苹果手机
export function formatTime (fmt, date) { date = new Date(date + '+08:00') // 兼容safari var o = { 'M+' ...
- C51学习
十六个数字循环显示 #include<reg52.h>#include<intrins.h>#define uint unsigned int#define uchar uns ...
- 【FF14】工匠配方爬取
目标:爬取最终幻想14工匠配方到excel表格.(一个装修仔的尊严) 代码: from bs4 import BeautifulSoup import urllib.request import xl ...
- js拖拽案例、自定义滚动条
简单实例: <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF ...
- Contest2195 - 2019-4-25 高一noip基础知识点 测试8 题解版
(因为david_alwal太懒了,所以本期题解作者为Th Au K,码风不同请自行适应) 传送门 T1 BFS?贪心?我也说不清 反正就是对每一个“#”搜一下他的旁边有没有“#”就行了 代码 T2 ...
- word20170104办签证 Visa application有用的词和句子
有用的词:visa category: 签证类型tourist visa: 旅游签证visa interview: 签证面试multiple entries: 多次往返visa on arrival: ...
- 解决sqlite 删除记录后数据库文件大小不变
最的做的项目中要有到sqlite数据存储,写了测试程序进行测试,存入300万条记录,占用flash大小为 86.1M,当把表中的记录全部删除后发后数据库文件大小依然是 86.1M: 原因是:sqlit ...
- PostCSS 实战
专题截图: 项目截图: 目录说明: dest/ 发布代码文件夹: src/ 预编译代码文件夹; node_modules node 插件; gulpfile.js ...
- ZOJ1008
题目: ZOJ 1008 分析: 重排矩阵, 虽然题目给的时间很多, 但是要注意剪枝, 把相同的矩阵标记, 在搜索时可以起到剪枝效果. Code: #include <bits/stdc++.h ...
- flutter 登录后跳转到根路由
flutter 登录以后 会有返回箭头显示 因为 路由的切换导致不是路由的第一个页面,解决办法清空路由. Navigator.of(context).pushAndRemoveUntil( new ...