UITableView(一)
来源:互联网 发布:js如何将一个div隐藏 编辑:程序博客网 时间:2024/06/06 09:08
1.创建UITableViewController要继承
<UITableViewDataSource,UITableViewDelegate>
2.下方是UITableViewController.m代码
- (void)viewDidLoad{ [super viewDidLoad];// Do any additional setup after loading the view. self.view.backgroundColor = [UIColor redColor]; UITableView * tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 20, 320, self.view.bounds.size.height-20) style:UITableViewStylePlain]; tableView.dataSource = self; tableView.delegate =self; tableView.separatorColor = [UIColor greenColor]; tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine; tableView.separatorInset = UIEdgeInsetsMake(0, 0, 0, 0); tableView.rowHeight = 60; [self.view addSubview:tableView]; [tableView release]; }-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ NSLog(@"%s,%d",__FUNCTION__,__LINE__); //第一区高50 第二区高70 //第三区高40 第四区高100 if (indexPath.section == 0 ) { return 50; }else if (indexPath.section == 1) { return 70; }else if (indexPath.section == 2) { return 40; } return 100;}-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{ return 100;}-(CGFloat)tableView:(UITableView *)tableView heightForFootInSection:(NSInteger)section{ return 40;}//-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section//{// UIView * one = [[UIView alloc]initWithFrame:CGRectMake(100, 100, 100, 100)];// one.backgroundColor = [UIColor yellowColor];// [self.view addSubview:one];// [one release];// return one;//}//-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section//{// UIView * one = [[UIView alloc]initWithFrame:CGRectMake(0, 100, 100, 100)];// one.backgroundColor = [UIColor greenColor];// [self.view addSubview:one];// [one release];// return one;//}//设置多少个分区 可选实现,默认为一-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ NSLog(@"333333%s,%d",__FUNCTION__,__LINE__); return 4;}//必须实现,设置所有分区的行数-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ NSLog(@"%s,%d",__FUNCTION__,__LINE__); NSLog( @"section = %d",section); if (section<2) { return 3; } return 5;}//必须实现,设置每行要显示的内容-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ NSLog(@"zzzzz%s,%d",__FUNCTION__,__LINE__); //tableView 中有一个NSSet,用来管理所有等待重用的cell对象 //定义cell的唯一标识 static NSString * cellIndetifier = @"cell"; //tableView通过cell的标识从NSSet(重用队列)中获取cell对象 UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:cellIndetifier]; if (!cell) { //如果不存在,创建cell对象 cell = [[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIndetifier]autorelease]; NSLog(@"*******section = %d*******row = %d*****",indexPath.section,indexPath.row); }// indexPath.section 第几个分区// indexPath.row 第几行 NSLog(@"w=%d,%d",indexPath.section,indexPath.row); cell.textLabel.text = [NSString stringWithFormat:@"第%d个分区,第%d行",indexPath.section,indexPath.row]; return cell;}//分区索引-(NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView{ return @[@"0",@"1",@"2",@"3"];}-(NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section{ return [NSString stringWithFormat:@"第%d区的尾",section];}//每个索引-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{ return [NSString stringWithFormat:@"第%d区头",section];}
使用以下代码会显示以下图片:
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
使用以下代码会显示以下图片:
-(NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
什么都不使用
0 0
- UITableView(一)
- UITableView <一>
- UITableView详解(一)
- UITableView(一)
- UItableView使用一
- ios学习:UITableView(一)
- UITableView(一)---- 基础
- UITableView基础(一)
- swift UITableView(一)
- UITableView练习一
- UITableView基本介绍(一)
- UITableView(一)----基本介绍
- UITableView reloadData 无效一例
- UITableView的基本使用一
- UITableView详解(UITableViewCell(一)重中之重)
- UITableView那些事(一)
- ios学习之UITableView(一)
- UITableView学习笔记(一)
- Android控件系列之RadioButton&RadioGroup
- Python文件操作 HelloWorld
- 使用dev_add_pack注册新的以太网类型
- Linux进程状态(ps stat)之R、S、D、T、Z、X
- 命令行 给apk 签名
- UITableView(一)
- 【Unity3D自学记录】异步加载卡顿问题解决
- 带注释的汇编指令大全
- Installation error: INSTALL_FAILED_UID_CHANGED 的解决办法
- RandomAccessFile
- 设计模式--对代理模式的思考之java动态代理
- 给定两个字符串,从A中删除存在于B中的字符
- 追逐
- ecshop 二次开发之三级商品分类树