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( ...
随机推荐
- Docker 容器的数据卷
数据卷的特点: 1. 数据卷在容器启动时初始化,如果容器使用的镜像在挂载点包含了数据,这些数据会拷贝到新初始化的数据卷中 2. 数据卷可以在容器之间共享和重用 3. 可以对数据卷里的内容直接进行修改 ...
- Glusterfs冗余镜像(AFR)修复原理以及脑裂分析
研究Glusterfs半年多了,通过实际操作以及源代码分析,对它有了越来越深的了解,由衷的赞叹Gluster的整体架构.今天时间不早了,想写点关于Glusterfs的冗余镜像产生脑裂的原因. 首先,简 ...
- Ryzen 移动平台上安装 Gentoo Linux
Linux 内核对于跟进支持 Ryzen 移动低压 CPU 的热情似乎和市面上寥寥无几的 Ryzen 笔记本热度十分吻合.虽然从 Linux 4.11 起就对 Ryzen 桌面 CPU 有较好的支持, ...
- vue-cli3.0 使用图形化界面创建和管理项目
1.打开终端输入vue ui vue ui 2.创建项目 3.选择一套预设,点击创建项目按钮 4.等待安装 5.安装完成后 6.可以添加插件 7.项目依赖管理 8.项目配置管理 9.项目任务管理 10 ...
- SP1026 FAVDICE - Favorite Dice
题目描述 一个\(n(n \leq 1000)\)面的骰子,求期望掷几次能使得每一面都被掷到. 输入输出样例 输入样例#1: 2 1 12 输出样例#1: 1.00 37.24 思路:期望\(dp\) ...
- 1101 Quick Sort(25 分
There is a classical process named partition in the famous quick sort algorithm. In this process we ...
- android SDK manager 无法获取更新版本的解决办法
http://mirrors.neusoft.edu.cn/eclipse/releases/luna/打开这个网址就可以看到adt的详细信息: http://developer.android.c ...
- 爬虫(AJEX)——豆瓣动态页面
工具:python3 解释:Ajax 是一种用于创建快速动态网页的技术,在无需重新加载整个网页的情况下,能够更新部分网页的技术. 目标:爬取使用Ajex结束的豆瓣网页 import urllib.re ...
- 033 Search in Rotated Sorted Array 搜索旋转排序数组
假设按照升序排序的数组在预先未知的某个关键点上旋转.(即 0 1 2 4 5 6 7 将变成 4 5 6 7 0 1 2).给你一个目标值来搜索,如果数组中存在这个数则返回它的索引,否则返回 -1.你 ...
- Unity Gizmos绘制指定长宽的网格
using UnityEngine; using System.Collections; public class GridMap : MonoBehaviour { ; //宽度 ; //长度 vo ...