iOS UIKit:UITableView
UITableView是UIScollView的子类,用于显示一列数据。
装在UITableView 里面的元素是UITableViewCell。
UITableViewCell 预设有4种样式Style:
UITableViewCellStyleDefault:预设使用这种,若左侧ImageView没图的话,只有一行字(textLable.text)。
UITableViewCellStyleValue1:左侧为textLable.text并且左对齐,右侧为detailTextLable.text并且右对齐。
UITableViewCellStyleValue2:左侧为detailTextLable.text,右侧为textLable.text并且左对齐。
UITableViewCellStyleSubtitle:跟UITableViewCellStyleDefault大致相同,detailTextLable.text出现在textLable.text下方。
UITableViewDataSource:
UITableViewDataSource 协议定了2个要求实现的方法(tableView:cellForRowAtIndexPath 和tableView:numberOfRowsInSection)。通过实现这些方法,你告诉表视图显示多少行数据和每一行中的数据。
- (NSInteger)tableView:(UITableView *)tableViewnumberOfRowsInSection:(NSInteger)section{return [model getRowCount]; }- (UITableViewCell *)tableView:(UITableView *)tableViewcellForRowAtIndexPath:(NSIndexPath *)indexPath {static NSString *CellIdentifier = @"Cell";if([indexPath section] == 0){UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];if (cell == nil) {cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:CellIdentifier] ;}NSUInteger row = [indexPath row];cell.textLabel.text = [model getNameAtIndex:row]; }else{cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (!cell) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
urlField = [[[UITextField alloc] initWithFrame:CGRectZero] autorelease]; [[cell contentView] addSubview:urlField]; } return cell; }
其他可选的方法包括:
Configuring a Table View – numberOfSectionsInTableView: – sectionIndexTitlesForTableView: – tableView:sectionForSectionIndexTitle:atIndex: – tableView:titleForHeaderInSection: – tableView:titleForFooterInSection: Inserting or Deleting Table Rows – tableView:commitEditingStyle:forRowAtIndexPath: – tableView:canEditRowAtIndexPath: Reordering Table Rows – tableView:canMoveRowAtIndexPath: – tableView:moveRowAtIndexPath:toIndexPath:
UITableViewDelegate:
负责处理UITableView的表现。
协议中的可选方法让你管理表行的高度,配置节点头部和底部,对表单元重新排序等等。
- ( void ) tableView: ( UITableView * ) tableView didSelectRowAtIndexPath: ( NSIndexPath * ) indexPath {if ([ tableView isEqual: self . myTableView ]){NSLog ( @"%@" ,[ NSString stringWithFormat: @"Cell %ld in Section %ld is selected" ,( long ) indexPath . row , ( long ) indexPath . section ]);} }
源码下载
转载于:https://www.cnblogs.com/shangdahao/archive/2013/05/28/iOSUIKit.html
iOS UIKit:UITableView相关推荐
- iOS UIKit:viewController之动画(5)
当弹出一个view controller时,UIKit提供了一些标准转换动画,并且也支持用户自定义的动画效果. 1 UIView动画 UIView是自带动画实现功能,其中有两种方式实现: ...
- 【iOS UIKit】UITableView属性及方法大全
2019独角兽企业重金招聘Python工程师标准>>> UITableView:表视图 继承UIScrollView并遵守NSCoding协议 1 属性 frame--------- ...
- 玩转iOS开发:iOS 11 新特性《UIKit新特性的基本认识》
文章分享至我的个人技术博客: https://cainluo.github.io/15099354591154.html 前两篇, 我们讲了Xcode 9的一些新特性, 可以更加方便我们去写" ...
- iOS 和 Android:UITableView与RecycleView的重用机制比较
引言:iOS和Android各有自己的列表组件.众所周知,列表组件一直都是移动端各个端中,组件重用.内存优化的重点.今天就来分析下iOS和Android各自的重用机制. Android:Recycle ...
- iOS开发系列--UITableView全面解析
iOS开发系列--UITableView全面解析 2014-08-23 23:20 by KenshinCui, 2202 阅读, 18 评论, 收藏, 编辑 --UIKit之UITableView ...
- (0074)iOS开发之UITableView的优化
写的很好引用 https://www.jianshu.com/p/af6b095aaaf3 前言 这篇文章对 UITableView 的优化主要从以下3个方面分析: 基础的优化准则(高度缓存, cel ...
- iOS 开发:『Runtime』详解(二)Method Swizzling
本文用来介绍 iOS 开发中『Runtime』中的黑魔法Method Swizzling. 通过本文,您将了解到: Method Swizzling(动态方法交换)简介 Method Swizzlin ...
- iOS UIKit框架注解
本文来自简书,原文地址:http://www.jianshu.com/p/e5b995ecf44d 导语 我们追求技术的提升,关注技术的发展历程:作为从事技术工作的伐码猿,有个想法(仅是个人想法),这 ...
- 玩转iOS开发:NSURLSession讲解(三)
文章分享至我的个人技术博客: https://cainluo.github.io/14986211698053.html 前言 虽然前面两讲都是说了NSURLSession的一些理论上的知识, 但我们 ...
最新文章
- 移动互联网漫谈(3)
- Flutter 21: 图解 ListView 下拉刷新与上拉加载 (三)【RefreshIndicator】
- OPhone2.0应该重在中文应用体验
- 使用parted命令对硬盘进行操作
- spark 1.4 编译
- WinFormsChartSamples
- OWASP Top 10关键点记录
- 工作中:如何在实际工作中处理 NULL,并给出一些指南
- 微服务网关总结之 —— zuul
- 微信抢红包算法 java_java 实现仿照微信抢红包算法,实测结果基本和微信吻合,附demo...
- java 性能瓶颈_如何通过 Java 线程堆栈来进行性能瓶颈分析?
- MAVEN项目的搭建
- 【Oracle】SQL语句优化
- VS2010-MFC(常用控件:标签控件Tab Control 下)
- Win10专业版永久激活
- 各种转码(bytes、string、base64、numpy array、io、BufferedReader )
- wp下载吧主题模板_内含newzhan2.60无授权版本
- SMT32同步采样ADC芯片ADS8329 | 立创开源
- 台式计算机打印机共享,电脑不能共享打印机怎么办 电脑设置共享打印机详细教程...
- hadoop学习步骤