最近在做iphone GRE背单词过程中涉及到很多UITableView的操作,借此机会好好梳理总结一下。本节主要介绍UITableView的基本使用方法。
一)UITableView所在的UIViewController声明两个delegate:UITableViewDelegate和UITableViewDataSource。
二)将UITableView对象的delegate设置成self。
三)根据实际需要实现delegate的具体方法,这里简要介绍一下常用的方法和属性。
(1)- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 该方法返回tableview有多少个section。
(2)- (NSInteger)tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section 该方法返回对应的section有多少个元素,也就是每个section对应有多少个cell。
(3)- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 该方法返回指定的row高度。
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section 该方法返回指定的section的header view的高度。
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section 该方法返回指定的section的footer view的高度。
(4)- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 该方法返回指定row的cell,在此函数中用户可以根据自己的需求定义cell的属性和显示风格等(主标题cell.textLabel,副标题cell.detailTextLabel,背景cell.imageView,图标cell.accessoryType等等)。
(5)- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section 该函数返回指定section的header的titile。
(6)- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section 该函数返回指定section header的view
(7) -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 用户选中某cell时的回调函数。
(8)- (UITableViewCell *)cellForRowAtIndexPath:(NSIndexPath *)indexPath 该方法获取某一cell对象。
(9)如果想让cell能响应选中事件,但是选中后的颜色不发生改变的话,设置cell.selectionStyle = UITableViewCellSelectionStyleNone。
(10)如果想删除cell之间的分割线,设置
tableview.separatorStyle = UITableViewCellSeparatorStyleNone。
以上介绍的方法及属性仅仅是GRE用到的,另外还有很多方法和属性未涉及。本篇文章只是抛砖引玉,等我们需要用到的时候可以参考xCode的联机帮助手册。
下节我给大家介绍一下UITableViewCell定制的用法。
分享到:
相关推荐
UITableView、UITableView基本用法、UITableView详解,UITabelView常用方法
UITableView是iPhone中比较常用的,用的比较多的控件, 本例中说明iPhone UITableView的使用方法实例。 该实列中是手动增加UITableViewDataSource和UITableViewDelegate协议来实现的。
UITableView:隐藏删除按钮和设置删除按钮的标题对应的Demo。
iOS开发中UITableview控件的基本使用及性能优化方法共15页.pdf.zip
UITableViewHeader 具有视差和拉伸效果的 UITableView 标题该项目基于: :
在动态单元格高度的练习中,开发者将学习如何根据单元格内容的不同动态计算并设置单元格的高度,以及如何使用UITableView.automaticDimension来让系统自动计算高度。通过这种方式,开发者可以更好地控制UI的响应性和...
iOS基本控件UITableView示例,展示了基本tableview的方法。
UITableView的简单使用
UITableView的使用,UITableView所在的UIViewController声明两个delegate:UITableViewDelegate和UITableViewDataSource。
UITableView高度自适应解决方法 iOS 源码 下载
UITableView Demo 快捷菜单 粘贴 Cell
UITableView-MVVM UITableView-使用MVVM
UITableView的使用方法及cell复用机制
在iOS开发中会用到的UISCrollView与UITableView嵌套使用的方法
UITableView基本用法大全
UI 使用总结之--UITableView
UITableView的使用 包括简单的搭建UITableView、搭建分组的UITableView、搭建分段的UITableView、可删除行等等
UITableView相关操作
android-uitableview, 关于如何使用UITableView组件库和示例项目 面向Android的UITableView 用法安装 Android Studio在项目的root 目录中粘贴或者克隆这个库到 /libs 文件夹中。 创建新文件夹:/libs 如果还没有存在...
【iphone应用开发】iphone应用开发之六:UITableView的详细讲解(一)