UITableView 的项目运用
来源:互联网 发布:playclub人物数据 编辑:程序博客网 时间:2024/06/14 10:39
前面写了一个最简单的tableview,现在教大家在项目中运用的最多的tableview,废话不多说,上图
首先,写一个tableview的属性 :
@property (nonatomic,strong)UITableView *tableView;
初始化
- (UITableView *)tableView{
if (!_tableView) {
_tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 64, 375, 500) style:UITableViewStylePlain];
_tableView.dataSource = self;
_tableView.delegate = self;
//这里如果不需要cell的虚线可以加上这句话:
_tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
}
return _tableView;
}
其次,最重要的cell的初始化:
这里说明一下cell的风格:一共四种,大家可以自己写来看一下有什么不同
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
if (!cell) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
}
cell.textLabel.text = @"这是一个cell";
return cell;
}
当然,现在设置cell的高度以及数量
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return 5;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return 35;
}
如果你只是需要一个简单的cell,那么到这里,就可以了,
但实际项目中网网这些是不够的,下面我们设置tableview每一section之间的headview
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 3;
//这里设置一共有几个section,这里说明一下,我们上面设置的cell的数量是在section下面的数量,这里设置了section有3个,那么说明每一个section下面的cell都有5个(上面设置的cell数量)
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
return10; //这里设置的是你的head view的高度
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
UIView *view = [UIView new];
view.backgroundColor = [UIColor blackColor];
return view; //这个view设置的就是headview,这里可以在这个view上面添加文字,图片等等
}
//好了,到此为止,一个tableview就设置好了
- UITableView 的项目运用
- “车城”项目问题总结之UITableView不同样式cell的运用
- iOS开发 | UITableView的无数据占位图在项目中的实际运用
- erp项目的运用
- ios中封装网络和UITableView的综合运用
- Winform项目HTMLEdior的运用
- JavaWeb项目中定时器的简单运用
- 随机函数的运用项目1
- 3 项目中shiro的运用
- UITableView项目中行的操作 (添加移动和删除)
- UITableView项目中行的操作 (添加移动和删除)
- 项目中运用到的对文件的操作
- Mina框架项目运用
- 项目中成功的运用proxool连接池
- 项目中成功的运用proxool连接池
- 项目中成功的运用proxool连接池
- 项目中成功的运用proxool连接池
- 项目总结:ORACLE通过JOB定时创建表的运用
- 最具影响力的机器人公司
- Nginx+nginx-gridfs
- 重拾梦想 C++
- 从Ubuntu 14.04 LTS版升级到Ubuntu 16.04 LTS
- [DynamicProgramming]动态规划题目泛做
- UITableView 的项目运用
- 1008 猜数字
- 训练2 23题
- 敏感词过滤
- JBoss4.0.0部署
- 从上往下打印二叉树
- PHP简介
- Android-Toast的属性设置
- BaseAdapter和Viewholder的抽取(模版设计模式)