1.我们知道tableView是IOS中的高级视图,其继承与ScrollView,故我们知道他有具有ScrollView的所有功能。而且还扩展了许多。当然在这里就不一一介绍了。

  2.tableView的表现格式分两种Plain和Grouped两种风格

  3.tableView的两种代理类delegate和dataSource.这两种代理至关重要,我们在做tableView和这些代理是分不开的。

  4.代理中比较常用的代理方法:

(1)dataSource的两个必须使用的代理

  @required

    //显示UITableView的Cell的个数

  - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

    //Cell和model的数据的交互

  - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

(2)delegate的常用代理方法

  @optional

    //用于设定tableView的高度

  - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

    //当选中Cell时候调用的方法

  - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

4.一般来说这四个代理已经能够处理函数tableView没有问题了,但是有时我们在做tableView时候,tableView的第一个Cell或者最后一个Cell和其他Cell不同,所以我们有可能用到下面的两个函数

//给tableview头的Cell和Model的数据交互

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section

//定义tableView的头部的高度

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section

//给tableview尾部的Cell和Model的数据交互

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section

//定义tableView的尾部的高度

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section

5.还有一种方法,应为tableView的对象自带的有这两个属性

例如:

ableView的对象自带的有这两个属性的属性要注意的是他接收的对象UIView

//截图

self.tableView.tableFooterView

self.tableView.tableHeaderView

以上基本上就可以做出完整的tableView了。那下面我们看一看tableView的扩展吧

6.我们知道tableView继承于scrollview,但是scrollView有时候加载过多的东西时候使用内存较大,会导致手机卡死;这时候我们一般有三个方法解决,一,重用scrollView  二,使用瀑布流 三,使用横向tableView

使用横向tableView:

一下例子只是我从工程中取出来的文件,可能运行不了,但是可以借鉴其步骤

其中代理函数不会发生改变,但是其中心和Frame都要发生改变

Frame需要X与Y 宽度和长度都要反过来

横向tableView主要有几句很重要的代码

这两句话:第一句话是将tableView横向旋转,第二句话是改变tableView中心。这两句话放在tabbleView的对象定义的时候,可见下面“设置界面”代码

table.transform = CGAffineTransformMakeRotation(- M_PI / 2);
table.center = CGPointMake(self.view.frame.size.width / 2 , self.view.frame.size.height / 2 + 30);

这一句话是放在Cell和Model数据交互中,其作用是将Cell也横向旋转
cell.contentView.transform = CGAffineTransformMakeRotation(M_PI / 2);

//设置界面
- (void) SettingsView
{
self.tableViewX = [[UITableView alloc] initWithFrame:CGRectMake(, , HEIGHT -, WIDTH)];
self.tableViewX.transform = CGAffineTransformMakeRotation(- M_PI / );
self.tableViewX.center = CGPointMake(WIDTH / , (HEIGHT + ) / + );
self.tableViewX.dataSource =self;
self.tableViewX.delegate = self;
self.tableViewX.pagingEnabled = YES;
self.tableViewX.showsVerticalScrollIndicator= NO;
self.tableViewX.bounces = YES;
[self.view addSubview:self.tableViewX]; } //显示有几个Cell
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return ;
} //数据交互
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
//数据
NSArray * newpho = allNewsarray[];
NSArray * newarr = allNewsarray[];
NSDictionary * newsPhotosDic = newpho[indexPath.row];
NSDictionary * newsdic = newarr[indexPath.row]; NSArray * photos = [newsPhotosDic objectForKey:@"data"]; NSString * identifier = [NSString stringWithFormat:@"Cell%lu",indexPath.row]; YZXViewCellX * Cell = [tableView dequeueReusableCellWithIdentifier:identifier];
if (Cell == nil)
{
Cell = [[YZXViewCellX alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier andArray:photos];
}
Cell.nowArray = [newsdic objectForKey:@"data"];
Cell.PhotoArray = [newsPhotosDic objectForKey:@"data"];
NSLog(@"+++++++++++++++%lu %lu",Cell.nowArray.count, Cell.PhotoArray.count);
Cell.contentView.transform = CGAffineTransformMakeRotation(M_PI / ); Cell.block = ^(YZXViewCellX * newCell, newsList * aa)
{
NSLog(@"详情");
DetailedNewsController * det = [[DetailedNewsController alloc] init];
det.New = aa;
[self.navigationController pushViewController:det animated:YES];
}; return Cell;
}
//因为横向tableView代替scroll故,高度为屏幕宽度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return WIDTH;
}

IOS开发UI篇之tableView 的用法详解的更多相关文章

  1. iOS开发UI篇 -- UISearchBar 属性、方法详解及应用(自定义搜索框样式)

    很多APP都会涉及到搜索框,苹果也为我们提供了默认的搜索框UISearchBar.但实际项目中我们通常需要更改系统默认搜索框的样式.为了实现这一目标,我们需要先搞懂 UISearchBar 的属性及方 ...

  2. iOS开发UI篇-实现tableView的层级显示

     进来要实现一个tableView 的cell层级显示,网上找的思路都各不相同.下面说一下我的实现思路.  根据根标题存储cell的展开状态,添加到字典中. 话不多说,直接上代码. #define S ...

  3. ios开发 <AppName>-Prefix.pch文件的用法详解

    我们知道,每新建立一个工程,比如说HelloWord,在分类SupportingFiles里都会有一个以工程名开头-Prefix.pch结尾的文件,如HelloWord-Prefix.pch.对于这个 ...

  4. iOS开发UI篇—iPad开发中得modal介绍

    iOS开发UI篇—iPad开发中得modal介绍 一.简单介绍 说明1: 在iPhone开发中,Modal是一种常见的切换控制器的方式 默认是从屏幕底部往上弹出,直到完全盖住后面的内容为止 说明2: ...

  5. ios开发UI篇—使用纯代码自定义UItableviewcell实现一个简单的微博界面布局

    本文转自 :http://www.cnblogs.com/wendingding/p/3761730.html ios开发UI篇—使用纯代码自定义UItableviewcell实现一个简单的微博界面布 ...

  6. iOS开发UI篇—Kvc简单介绍

    ios开发UI篇—Kvc简单介绍 一.KVC简单介绍 KVC key valued coding 键值编码 KVC通过键值间接编码 补充: 与KVC相对的时KVO,即key valued observ ...

  7. iOS开发UI篇—UITableview控件简单介绍

    iOS开发UI篇—UITableview控件简单介绍 一.基本介绍 在众多移动应⽤用中,能看到各式各样的表格数据 . 在iOS中,要实现表格数据展示,最常用的做法就是使用UITableView,UIT ...

  8. iOS开发UI篇—UITableview控件基本使用

    iOS开发UI篇—UITableview控件基本使用 一.一个简单的英雄展示程序 NJHero.h文件代码(字典转模型) #import <Foundation/Foundation.h> ...

  9. iOS开发UI篇—UITableviewcell的性能优化和缓存机制

    iOS开发UI篇—UITableviewcell的性能问题 一.UITableviewcell的一些介绍 UITableView的每一行都是一个UITableViewCell,通过dataSource ...

随机推荐

  1. 在ASP.NET MVC中验证checkbox 必须选中 (Validation of required checkbox in Asp.Net MVC)

    转载自 http://blog.degree.no/2012/03/validation-of-required-checkbox-in-asp-net-mvc/ Why would you want ...

  2. hdoj 5327 Olmpiad

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5327 #include<stdio.h> #include<cstring> ...

  3. 开机自动播放音乐的vbs

    今天无意间看到了vbs这小玩意,就突发奇想,自学了一下,倒弄出如下的小玩意,大牛勿喷!这个可用做撩妹神技也可以用于提醒自己!使用方法:复制程序到txt文本里面保存,然后改后缀为vbs,丢到C:\Pro ...

  4. Objc基础学习记录--UIViewController

    多个view之间切换用Embed in -->UINavigationController sugues的方式  有push和modal 及其cuestom 关于其重要的方法: -(void) ...

  5. CentOS6 下Vim安装和配置

    1.系统只安装了vim-minimal,执行以下命令安装另外两个组件 yum install vim-common yum install vim-enhanced 2.安装ctags yum ins ...

  6. urlrewritingnet 域名http状态302 问题(转)

    UrlRewritingNet is an Url rewriting tool for ASP .Net and Elmahis a module for logging unhandled err ...

  7. 《高性能MySQL》

    <高性能MySQL>(第3版)讲解MySQL如何工作,为什么如此工作? MySQL系统架构.设计应用技巧.SQL语句优化.服务器性能调优.系统配置管理和安全设置.监控分析,以及复制.扩展和 ...

  8. table布局 height=100%无效分析

    (从死了一次又一次终于挂掉的百度空间中抢救出来的,发表日期 2014-08-11) 原文链接:http://www.cnblogs.com/gaojun/archive/2012/05/07/2487 ...

  9. codis3.1集群搭建

    Codis31搭建 codis 3.1 安装搭建 一.基本信息 1. 服务器基本信息 ip地址 安装服务 172.16.200.71 zk1.codis-dashboard.codis-fe.codi ...

  10. 内网能PING通TELNET通不能访问解决

    遇到一个离奇故障,内网,两个主机在同一IP段内,能互相PING通,TELNET对方的WEB服务器端口,通. 但用IE访问时不能,显示HTTP400.这明显是客户端系统的问题啊!但如何解决呢?我强烈怀疑 ...