UITableView
来源:互联网 发布:相册模板制作软件 编辑:程序博客网 时间:2024/06/04 18:56
表视图用于显示数据列表,数据列表中得每项都由行表示。ios没有行数限制,行数仅受可用存储空间的限制。表视图的表只有一列时,用户可以通过上下滑动屏幕的方式来查看更多地信息。
表视图的两种类型:
- 分组表:UITableViewStyleGrouped
- 无格式表:UITableViewStylePlain
表视图的Section和Row:
表中得每个部分成为数据源中得分区(Section)。在分组中,每个分组都是一个分区。在索引表中,数据的每个索引分组都是一个分区。
表中的每个可见行对应数据源中的行(Row)。
表视图的单元格:
表视图是显示表数据的视图对象,它是UITableView类的一个实例。表中的每个可见 行都是UITableViewCell类的实例。其中UITableViewCell的实例就是单元格。
表视图的DataSource和Delegate:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
单元格内容(默认)包括图像imageView、文本标签textLable、详细文本标签detailTextLable。单元格的样式(UITbaleViewCellStyle)
UITableViewCellStyleSubtitle
UITableViewCellStyleDefault
UITableViewCellStyleValue1
UITableViewCellStyleValue2
#import <UIKit/UIKit.h>
@interface ViewController :UIViewController<UITableViewDataSource,UITableViewDelegate>//添加两个代理
@property (retain,nonatomic)UITableView *myTbl;//将表视图设置成属性
@end
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad
{
[superviewDidLoad];
//创建表视图及表视图的格式UITableViewStyleGrouped
self.myTbl = [[UITableViewalloc]initWithFrame:CGRectMake(0,0,320,460)style:UITableViewStyleGrouped];
//添加到父视图
[self.viewaddSubview:self.myTbl];
//设置代理
self.myTbl.dataSource =self;
self.myTbl.delegate =self;
}
//设置表视图的分组
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 2;
}
//设置每个分组中得行数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 10;
}
//设置表视图中单元格的内容
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
//定义静态标识符
static NSString *identfire =@"cellIdentfire";
//单元格重用
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identfire];
if (cell == nil) {
cell = [[UITableViewCellalloc]initWithStyle:UITableViewCellStyleSubtitlereuseIdentifier:identfire];
}
//填写cell里的内容
//单元格的样式
cell.accessoryType =UITableViewCellStyleSubtitle;
//返回单元格的对象
return cell;
}
//单元格高度自适应
- (float)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSArray *arr = nil;//具体看情况
NSString *str = [arr objectAtIndex:indexPath.row];
CGSize size = [strsizeWithFont:[UIFontsystemFontOfSize:14]constrainedToSize:CGSizeMake(300,1000)];
return size.height +20;
}
- (void)didReceiveMemoryWarning
{
[superdidReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
- UITableView
- UITableView
- UITableView
- UITableView
- UITableView
- UITableView
- UITableView
- UITableView
- UITableview
- UITableView
- UITableView
- UITableView
- UITableView
- UITableView,
- UITableView
- UITableView
- UITableView
- UITableView
- leetcode Reorder List
- ubuntu中的VI编辑器insert模式,按上下左右键显示ABCD字母
- 用SecureRDP限制指定的计算机名,MAC,IP才能登陆服务器的远程桌面
- 班级学生德育量化管理系统_德育积分学分考核系统_学生操行日常行为规范考核系统
- linux系统的7种运行级别
- UITableView
- Spring Batch 之 框架流程简单介绍(二)
- POJ1700:Crossing River
- 给我一篇假论文,我能骗倒半个地球
- int main(int argc,char* argv[])详解
- Python基础学习笔记之(二)
- 《Head Rush Ajax》读书笔记
- Spring Batch 之 Sample(Hello World)(三)
- 5 关联式容器-set map multiset multimap