tableView的一些基本方法
2015-07-30 13:42
471 查看
tableView实现UITableViewDataSource和UITableViewDaraDelegate协议。
UITableViewDataSource中的
这个方法把一个cell添加到indexPath这个位置上去。indexPath中包含了第几个section indexPath.section和在这个section中第几个 cell,indexPath.row。
方法返回一个整形,内容是每个section内的Cell数目,section的默认值是1。
————以上这两个方法必须实现.
下面写的是设置section的方法
分完组以后不把每个section设置一个title看上和一个section一样,设置每个Section标题的方法是
cell的点击事件:
这个方法是点击单元格时会在单元格上打上钩。
UITableViewDataSource中的
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
这个方法把一个cell添加到indexPath这个位置上去。indexPath中包含了第几个section indexPath.section和在这个section中第几个 cell,indexPath.row。
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return [cellArr count] }
方法返回一个整形,内容是每个section内的Cell数目,section的默认值是1。
————以上这两个方法必须实现.
下面写的是设置section的方法
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ return [cellArr count]; }
分完组以后不把每个section设置一个title看上和一个section一样,设置每个Section标题的方法是
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { NSString *title = [NSString stringWithFormat:@"第%ld个section",(long)section + 1]; return title; }
cell的点击事件:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; cell.accessoryType = UITableViewCellAccessoryCheckmark; lastPath = indexPath; }
这个方法是点击单元格时会在单元格上打上钩。
相关文章推荐
- 峰回路转,Firefox 浏览器即将重返 iOS 平台
- 峰回路转,Firefox 浏览器即将重返 iOS 平台
- 不可修补的 iOS 漏洞可能导致 iPhone 4s 到 iPhone X 永久越狱
- iOS 12.4 系统遭黑客破解,漏洞危及数百万用户
- 每日安全资讯:NSO,一家专业入侵 iPhone 的神秘公司
- [转][源代码]Comex公布JailbreakMe 3.0源代码
- 主页木马的制作方法
- ip地址基础知识
- 解密网页加密的两个方法
- VBS基础编程教程 (第1篇)
- 定义标题的最好方法
- VBS基础编程教程 (第3篇)
- 路由器基础精析
- Ruby简明教程之方法(Method)介绍
- Ruby基础知识之方法、代码段
- C#获取文件夹及文件的大小与占用空间的方法
- Delphi控件ListView的属性及使用方法详解
- VB6实现连接Access数据库的ADODB代码实现方法
- MySQL重定位数据目录的方法