iOS 制作表格 (数据源控制行,列数)
记得去年面试的过程中,有一个面试官问我怎么制作表格。由于之前也没有做过,当时有点懵逼,今天想起来了,就用tableview制作了一个,望不要有人像我一样掉坑了,
直接上代码:
//
// ViewController.m
// 表格-test
//
// Created by abc on 16/8/2.
// Copyright © 2016年 LiuWenqiang. All rights reserved.
// #import "ViewController.h"
#define WQwidth [UIScreen mainScreen].bounds.size.width
#define WQheight [UIScreen mainScreen].bounds.size.height @interface ViewController ()<UITableViewDataSource,UITableViewDelegate,UIScrollViewDelegate> @property(strong,nonatomic) UITableView * tableview;
@property(strong,nonatomic) UIScrollView * scrollview; @end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad]; self.view.backgroundColor = [UIColor grayColor]; UIScrollView *scrollview =[[ UIScrollView alloc]init];
scrollview.frame = CGRectMake(, , WQwidth, WQheight);
scrollview.backgroundColor =[ UIColor grayColor];
scrollview.contentSize = CGSizeMake(WQwidth, WQheight+); scrollview.delegate =self;
self.scrollview =scrollview;
[self.view addSubview:scrollview]; for (int i=; i<; i++) { UITableView *tableview =[[UITableView alloc]init];
tableview.frame = CGRectMake(i*WQwidth/+0.5, , (WQwidth-*0.5)/, scrollview.contentSize.height);
tableview.backgroundColor = [UIColor whiteColor];
tableview.delegate =self;
tableview.dataSource = self;
tableview.scrollEnabled = NO;
tableview.tag = i;
self.tableview =tableview;
self.tableview.tableFooterView = [[UIView alloc]init];
[self.scrollview addSubview:tableview]; } }
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return ; }
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"]; if (!cell) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
cell.textLabel.text = [NSString stringWithFormat:@"第%ld行",(long)indexPath.row];
cell.textLabel.font = [UIFont systemFontOfSize:];
cell.separatorInset = UIEdgeInsetsMake(,- , , );
} return cell; } -(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
if (tableView.tag ==||tableView.tag ==) {
return @"图书";
}else{ return nil;
} } -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{ if (tableView.tag ==||tableView.tag ==) {
return WQheight/;
}else{
return ;
}
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return WQheight/; }
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{ [tableView deselectRowAtIndexPath:indexPath animated:YES]; NSLog(@"---------(%ld,%ld)",(long)tableView.tag,(long)indexPath.row); }
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{ if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
[cell setSeparatorInset:UIEdgeInsetsZero];
}
if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
[cell setLayoutMargins:UIEdgeInsetsZero];
}
//按照作者最后的意思还要加上下面这一段
if([cell respondsToSelector:@selector(setPreservesSuperviewLayoutMargins:)]){
[cell setPreservesSuperviewLayoutMargins:NO];
}
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} @end
由于表格一般都是整体滚动的,就关闭了tableview的滚动,把tableview就放到uiscrollview上了,但是感觉这样会影响运行效率,有时间再优化吧,
大家有什么好的意见给我说一下,谢谢啦
iOS 制作表格 (数据源控制行,列数)的更多相关文章
- 用VBA计算WPS 表格ET EXCEL中的行数和列数的多重方法
用VBA计算WPS 表格ET EXCEL中的行数和列数 每种方法中上面的是Excel的行数,下面的是Excel的列数. 方法1: ActiveSheet.UsedRange.Rows.Count Ac ...
- VBA取得EXCEL表格中的行数和列数
VBA取得EXCEL表格中的行数和列数 初学EXCEL宏的童鞋,总是很想知道表格中含有数据的行数和列数,尤其是行数和列数不确定的情况下.这样可以避免很多的错误,并且可以提高效率.但每次用到的时候到网上 ...
- C# 得到EXCEL表格中的有效行数和列数
每种方法中上面的是Excel的行数,下面的是Excel的列数.方法七:经过加工修改已经可以读出来的是有效数据行 using Excel = Microsoft.Office.Interop.Excel ...
- POI获取Excel列数和行数的方法
//获取指定行,索引从0开始 hssfRow=hssfSheet.getRow(1); //获取指定列,索引从0开始 hssfCell=hssfRow.getCell((short)6);//获取总行 ...
- JAVA使用POI获取Excel的列数与行数
Apache POI 是用Java编写的免费开源的跨平台的 Java API,Apache POI提供API给Java程式对Microsoft Office格式档案读和写的功能. 下面这篇文章给大家介 ...
- Office EXCEL VBA如何取得EXCEL中的行数和列数
VBA取得EXCEL表格中的行数和列数 请注意不要使用Columus等关键字作为变量,例如"Columus = ActiveSheet.UsedRange.Columns.Count&quo ...
- <td>标签clospan和rowspan 可横跨列数和行数
<td colspan="2"> <input type="text" name="reason_other" size= ...
- python如何输出矩阵的行数与列数?
Python如何输出矩阵的行数与列数? 对于pyhton里面所导入或者定义的矩阵或者表格数据,想要获得矩阵的行数和列数有以下方法: 1.利用shape函数输出矩阵的行和列 x.shape函数可以输出一 ...
- jquery获取table的行数、列数
$("#grd").find("tr").length; //行数 $("#grd").find("tr").find( ...
随机推荐
- Ryzen 移动平台上安装 Gentoo Linux
Linux 内核对于跟进支持 Ryzen 移动低压 CPU 的热情似乎和市面上寥寥无几的 Ryzen 笔记本热度十分吻合.虽然从 Linux 4.11 起就对 Ryzen 桌面 CPU 有较好的支持, ...
- 与pocket 对接技术文档
同步每日新增用户接口(kwai 提供) 注释:该接口 每天0点(北京时间)之后 向kwai服务器同步前一天 新增的IMEI号 url:http://m.kwai.com/rest/o/pocket/ ...
- jsp内置对象request使用方法2
<%@page import="java.text.SimpleDateFormat"%> <%@page import="java.util.Date ...
- git分支主干
~/Desktop/work/movies/movie(apps) $ git status //先查看是否有需要提交的东西# On branch appsnothing to commit (wo ...
- 洛谷P4114 Qtree1
题目描述 给定一棵\(n\)个节点的树,有两个操作: \(CHANGE\) \(i\) \(t_i\) 把第\(i\)条边的边权变成\(t_i\) \(QUERY\) \(a\) \(b\) 输出从\ ...
- Ehab and subtraction(思维题)
time limit per test 1 second memory limit per test 256 megabytes input standard input output standar ...
- BestCoder Round #86 1001
链接http://acm.hdu.edu.cn/showproblem.php?pid=5804 题意:给你一些商店和他的商品价格,然后给你一个记账本,问你记大了就是1,否则是0 解法:模拟,注意测试 ...
- oracle的存储过程优缺点
oracle的存储过程优缺点 1.存储过程可以使得程序执行效率更高.安全性更好,因为过程建立之后 已经编译并且储存到数据库,直接写sql就需要先分析再执行因此过程效率更高,直接写sql语句会带来安全性 ...
- 非关系型数据库---Memcached
一.概述 1.Memcached是一个高性能的分布式内存对象缓存系统,用于动态Web应用以减轻数据库的负载: 2.Memcached通过 在内存中缓存对象和数据 来减少读取数据库的次数,从而提升网站的 ...
- nginx图片缓存服务器配置实战
1.图片目录设置: 假定服务器主目录为nginx的默认目录:/usr/local/nginx-0.8.32/html/ 图片存放目录为:/usr/local/nginx-0.8.32/html/SD ...