UITableView 入门浅谈

春节过了,没时间更新了,估计要好一段时间不能写了。今天我给大家带来简单的UITabeleView用法,估计刚开始有点难懂,多练习就行了。

#import "ViewController.h"

@interface ViewController ()<UITableViewDataSource,UITableViewDelegate>//数据源代理协议方法
和代理协议方法

@end

@implementation ViewController

- (void)viewDidLoad {

[super
viewDidLoad];

[self
createTabView];

}

-(void)createTabView

{

UITableView *tableView = [[UITableView
alloc]initWithFrame:self.view.bounds
style:UITableViewStyleGrouped];

tableView.dataSource =
self;

tableView.delegate =
self;

tableView.rowHeight =
60;

tableView.sectionHeaderHeight =
50;

tableView.sectionFooterHeight =
40;

//设置头表视图

UIView *headerView = [[UIView
alloc]init];

headerView.frame =
CGRectMake(50,
50, 50,
50);

headerView.backgroundColor = [UIColor
greenColor];

tableView.tableFooterView = headerView;

//设置尾表视图

UIView *footerView = [[UIView
alloc]init];

footerView.frame =
CGRectMake(50,
50, 50,
0);

footerView.backgroundColor = [UIColor
greenColor];

tableView.tableFooterView = footerView;

[self.view
addSubview:tableView];

}

//设置组

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

{

return
10;

}

//设置行

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

{

return
5;

}

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

{

static
int count = 0;

count++;

NSString *cellID =
@"cellID";

//从tableview的复用队列取用cellid标识的可复用的cell

UITableViewCell *cell = [tableView
dequeueReusableCellWithIdentifier:cellID];

if (cell ==
nil) {

static
int count1 = 0;

count1++;

cell = [[UITableViewCell
alloc]initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:cellID];

//Set the selected cell view

UIView *selView = [[UIView
alloc]init];

selView.backgroundColor = [UIColor
cyanColor];

cell.selectedBackgroundView = selView;

}

if (indexPath.row %2) {

cell.backgroundColor = [UIColor
orangeColor];

}

else

{

cell.backgroundColor = [UIColor
purpleColor];

}

//当前组合行
在tableview上要显示的数据

NSString *string = [NSString
stringWithFormat:@"%ld组%ld行",indexPath.section,indexPath.row];

//Set the display content on the cell

cell.textLabel.text =string;

return cell;

}

//Sets the head title specified group

-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section

{

return [NSString
stringWithFormat:@"%ld组头部",section];

}

//返回指定分组的尾部标题

-(NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section

{

return [NSString
stringWithFormat:@"%ld组尾部",section];

}

//返回指定位置的行高,默认行高为44

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

{

if (indexPath.row %2) {

return
44;

}

else

{

return
66;

}

}

//返回每个分组的头部高度

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

{

return
40;

}

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

{

return
20;

}

//返回指定分组的头部视图

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

{

UILabel *label  = [[UILabel
alloc]init];

label.text = [NSString
stringWithFormat:@"第%ld组头部",section];

label.textColor = [UIColor
redColor];

label.font = [UIFont
systemFontOfSize:22];

return label;

}

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

{

UILabel *label = [[UILabel
alloc]init];

label.text = [NSString
stringWithFormat:@"第%ld组尾部",section];

label.textColor = [UIColor
redColor];

label.backgroundColor = [UIColor
grayColor];

label.font = [UIFont
systemFontOfSize:22];

return label;

}

@end

时间: 2024-08-03 10:26:18

UITableView 入门浅谈的相关文章

反射入门-浅谈反射用途_根据Ado游标对象创建list集合

本人大二菜鸟一只,今天在上课期间有个同学看着C#反射的内容说反射没什么用,一时之间也想不到什么更好的例子,就写了个根据泛型类型和游标反射创建List集合的Demo. 首先创建一个用于封装对应数据的entity,代码如下. using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Test { public

Java入门浅谈

首先了解Java的版本:JavaME.JavaSE(主要来创建桌面应用,有独立的安装程序,例如:Windows.msi等).JavaEE(在JavaSE基础上构建,主要提供Web服务,管理等).然后就是Java的语言特点,不同于C语言,C语言直接语言运行编译成机器码执行,效率高:而Java会首先生成一个class文件(也就是字节码),再解释成机器码在运行.

入门浅谈-产品经理与众不同的思维方式和“职业病”

在接触了各种不同的知识之后,在初步了解下,发现自己和产品经理这个岗位的契合度还是蛮高的,而且也正好是自己感兴趣的方向.能找到自己喜欢做的事情并不容易,所以,勇敢一点吧. 首先,产品经理独特的思维方式和所谓的"职业病"和它本身的定位有很大的关系. 作为一个"交叉位置"的职位,使得其需要考虑的不仅仅是某一方面的问题,而在综合考虑了多方面的问题和解决方案之后做出的决定在不少人眼里多少会显得有些与众不同.在做出这个决定的过程中, 不可避免会做出大量的取舍,而这又会激起各方的

浅谈SQL优化入门:1、SQL查询语句的执行顺序

1.SQL查询语句的执行顺序 (7) SELECT (8) DISTINCT <select_list> (1) FROM <left_table> (3) <join_type> JOIN <right_table> (2) ON <join_condition> (4) WHERE <where_condition> (5) GROUP BY <group_by_list> (6) HAVING <having_

浅谈IM软件怎样建立安全socket连接、登录

----------------------------------------------------欢迎查看IM软件业务知识<专栏>-------------------------------------------------------------------使用状态机来保持在线状态 [点击]                      拼图算法,将零碎小图,整理到一张大图上[点击]登录导航 [点击]                                          

浅谈WebLogic和Tomcat

浅谈WebLogic和Tomcat 分类: Java Web2011-11-30 21:19 54484人阅读 评论(19) 收藏 举报 weblogictomcat应用服务器ejbservletjava J2ee开发主要是浏览器和服务器进行交互的一种结构.逻辑都是在后台进行处理,然后再把结果传输回给浏览器.可以看出服务器在这种架构是非常重要的. 这几天接触到两种Java的web服务器,做项目用的Tomcat,看视频看的是WebLogic Server(WLS),都是web服务器,有什么区别和联

浅谈移动前端的最佳实践(转)

前言 这几天,第三轮全站优化结束,测试项目在2G首屏载入速度取得了一些优化成绩,对比下来有10s左右的差距: 这次优化工作结束后,已经是第三次大规模折腾公司框架了,这里将一些自己知道的移动端的建议提出来分享下,希望对各位有用 文中有误请您提出,以免误人自误 技术选型 单页or多页 spa(single page application)也就是我们常常说的web应用程序webapp,被认为是业内的发展趋势,主要有两个优点: ① 用户体验好 ② 可以更好的降低服务器压力 但是单页有几个致命的缺点:

浅谈Swift之己见

WWDC 2014,给了我们很多惊喜,对于开发者,Swift无疑给了我们太大的惊讶,前些天看见一篇文章道:今天在微博上不转发Swift相关的东西都不好意思说自己是程序员了,我自己的拙见,再加上苹果的敢于破旧立新,这门语言很快就会取代OC的位置,毕竟OC语法太别扭了,我是做windows路线以及J2EE的,从C#和JAVA去转向OC,天哪,简直就是噩梦,当我写J2EE烦了,我就去看看OC,顿时就找回幸福感,所以,就像有的人天生长的丽质,有的人,天生长的就是励志,好了,开玩笑,我们现在有一共同的特点

浅谈web前端开发

有部分同学和朋友问到过我相关问题.利用周末我就浅浅地谈谈我对web前端开发的理解和体会,仅仅能浅浅谈谈,高手请自己主动跳过本篇文章. 毕竟我如今经验并非非常足,连project师都算不上,更不用说大牛了.今天也不谈技术.技术非常多人比我掌握得更好,也大同小异.可是每一个人的理解体会是不一样的. 对前端开发的三个整体理解和体会 我对前端开发的整体体会有三: 第一:杂而难,难度甚至超过了一般的后台开发,假设有人认为前端开发简单仅仅能说明他还没有入门. 第二:web前端开发正在向响应式和移动端方向大步