IOS开发复习笔记(4)-TableView
总结几个TableView常用的代码
1.初始化方面
static string CellIndetifier=@"cellIndetifier";
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 1;//表中段数
}
-(NSInterger)tableView:(UITableVIew *)tableView numberOfRowsInSection:(NSInteger)section{
retrun 0;//每个段中的单元格数量
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell =[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:cellIdentifier];
}
cell.textLabel.text=@”showNSString”;//表中文字内容
UIImage *image=[UIImage imageNamed:@”picname.png”];
cell.imageView.image=image;//添加图片
cell.textLabel.font=[UIFont boldSystemFontOfSize:10];//设置字体大小
// Configure the cell.
return cell;
} //配置单元格
通过委托为每行的列表设置高度
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
// return 70;//简单的操作
//return indexPath.row//为每行设置不同高度
}
在TableViewCell中添加子视图如Lable,继承UITableViewCell类
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
}
return self;
}
2.tableviewcell的样式有很那些呢:
UITableViewCellDefault样式:左边一个显示图片的imageView,一个标题textLabel,没有detailTextLabel。
UITableViewCellStyleSubtitle:左边一个显示图片的imageView,上边一个主标题textLabel,一个副标题detailTextLabel。主标题字体大且加黑,副标题字体小在主标题下边。
UITableViewCellStyleValue1:左边一个显示图片的imageView,左边一个主标题textLabel,右边一个副标题detailTextLabel,主标题字体比较黑。
UITableViewCellStyleValue2:左边一个主标题textLabel字体偏小,挨着右边一个副标题detailTextLabel,字体大且加黑。
通过委托设置缩进的级别,关键词indentation 为缩进,缩排的意思
-(NSInteger) tableView:(UITableView *)tableView indentationLevelForAtIndexPath:(NSIndexPath *)indexPath
{
return num;//num是你要缩进的级别
}
3.tableViewCell的选择处理
-(NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath{
return indexPath;//返回选择的行数,由于是will所以是发生在选择行之前,可以增加一些如高亮操作,或者无法选中的功能
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
//在选中该行后进行的操作,可以使用indexPath.row作为索引进行取数
}
-(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath{
//取消该行的操作,比如选了其他行,注意didselect和didDeselect区别,初学者可能经常没注意到
}
4.使用自定义的Cell类
UITableView *tableView=(id)[self.view viewWithTag:1];//话说这是另一种连接的方法?
[tableView regsiterClass:[BIDNameCell class] forCellReuseIndentifier:@"cellresusename"]
//BIDNameCell为自定义的Cell类,tableView是你声明的表视图
5.
IOS开发复习笔记(4)-TableView的更多相关文章
- IOS开发复习笔记(1)-OC基础知识
在上班之余学习IOS已经有三个多月了,因为基础有些薄弱从OC的基本语法开始学习的,相继看了青柚子和红柚子的书,现在在看编程实战,趁这个机会好好的总结一下: 1.命名约定 对象类型和名称一致,以免混淆 ...
- IOS开发复习笔记(3)-ARC
1.ARC 当你自己调用了release或retain语句的时候,ARC有效时编译文件会遇到错误,你可以通过-fno-objc-arc和-fobjc-arc两个编译器标志在混搭中支持ARC和非ARC的 ...
- 李洪强iOS开发之 - 指定刷新tableview的某一组
李洪强iOS开发之 - 指定刷新tableview的某一组
- iOS开发学习笔记:基础篇
iOS开发需要一台Mac电脑.Xcode以及iOS SDK.因为苹果设备都具有自己封闭的环境,所以iOS程序的开发必须在Mac设备上完成(当然,黑苹果应该也是可以的,但就需要花很多的精力去折腾基础环境 ...
- ios开发学习笔记(1)
objective-c基础总结 第一二章 1.application:didiFinishLauchingWithOptions:程序启动后立即执行 2.启动界面代码格式:self.window = ...
- ios开发学习笔记(这里一定有你想要的东西,全部免费)
1,Search Bar 怎样去掉背景的颜色(storyboard里只能设置background颜色,可是发现clear Color无法使用). 其实在代码里还是可以设置的,那就是删除背景view [ ...
- iOS开发学习笔记
1 常用的第三方工具 1.1 iPhone Simulator 测试程序需要模拟器iPhone Simulator 1.2 设计界面需要Interface Builder,Interface Buil ...
- IOS开发-当遇到tableView整体上移时的解决方案
方案一在使用了navigationController后,当界面进行跳转往返后,时而会出现tableView上移的情况,通常会自动上移64个像素,那么这种情况,我们可以关闭tableView的自动适配 ...
- iOS开发零碎笔记
Mac常用操作 全屏截图:同时按住键盘左下方的command和shift ,然后点击键盘上方的数字键3,便可对整个屏幕截图,截图会自动保存在桌面:任意部分截图:同时按住键盘左下方的ommand和s ...
随机推荐
- BASE64Decoder的引用
project---->properties--->Libraries--->JRE System Library--->Access rules--->Edit---& ...
- iDempiere = OSGi + ADempiere 一款ERP&CRM&SCM系统、助力中小企业发展
怀揣着为中小企业量身定做一整套开源软件解决方案的梦想开始了一个网站的搭建.http://osssme.org/ iDempiere = OSGi + ADempiere 一款ERP&CRM&a ...
- MySQL Memory 存储引擎浅析
原创文章,转载必需注明出处:http://www.cnblogs.com/wu-jian/ 前言 需求源自项目中的MemCache需求,開始想用MemCached(官方网站:http://memcac ...
- 腾讯云 net.core
搭建 .NET Core 开发环境 安装 .Net Core 执行代码 任务时间:时间未知 .NET Core 的官方文档很详细,本实验带你建立一个.NET Core 1.1的Web运行环境,更多内容 ...
- 贯通tomcat --- 电子书
http://www.educity.cn/jiaocheng/j10865.html 第1章 认识Tomcat [本章导读] Tomcat服务器是一个免费的开放源代码的Web应用服务器.它是Apac ...
- 606. Construct String from Binary Tree 【easy】
606. Construct String from Binary Tree [easy] You need to construct a string consists of parenthesis ...
- Jenkins安装和配置系列(阳光温暖了心情)
转自:http://www.cnblogs.com/yangxia-test/category/668771.html Jenkins学习一:Jenkins是什么? Jenkins学习二:Jenkin ...
- Linux下同步模式、异步模式、阻塞调用、非阻塞调用总结
转自:http://www.360doc.com/content/13/0117/12/5073814_260691714.shtml 同步和异步:与消息的通知机制有关. 本质区别 现实例子 同步模式 ...
- iOS swift版本无限滚动轮播图
之前写过oc版本的无限滚动轮播图,现在来一个swift版本全部使用snapKit布局,数字还是pageConrrol样式可选 enum typeStyle: Int { case pageContro ...
- archive的时候报“ no identity found"错误 解决方式
第一步: 在xcode----target----general----identity----team里 增加你们公司的账号就能够了 第二步: Xcode > Preferences > ...