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( ...
随机推荐
- Ocelot - .Net Core开源网关
Ocelot - .Net Core开源网关 作者:markjiang7m2 原文地址:https://www.cnblogs.com/markjiang7m2/p/10857688.html 源码地 ...
- 简单的vue.js的表单提交数据至flask然后数据库入库,再将表里面的数据展示在网页
一.先在数据库中创建表格 在mysql中建users库并建立一个含有ID,username,email三个字段的user表 二.去vue的组件里面写页面的表单代码,注意form标签里的action需要 ...
- thinkphp5使用QueryList实现采集功能
QueryList是基于phpQuery的 1.下载`QueryList.php`和`phpQuery.php`这两个文件. 2.在`extend`下新建`QL`目录. 3.将下载好的`QueryLi ...
- 关于map 及 map 骚操作
关于map这个东西 很冷门.................. 但是,这个博客带你稍微了解一下map: map用法:一般当作一个下表无穷大的数组 关于它的骚操作:map的鬼畜用法,可以 ...
- rem字体在rem盒子里面不一样,或者不同的行解决
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- POJ1009 Edge Detection
题目来源:http://poj.org/problem?id=1009 题目大意: 某图像公司用run length encoding(RLE)的方式记录和存储了大量的图像.程序的目标是读入压缩后的图 ...
- .netcore中无法使用System.Drawing --解决方案
问题重现: 无法正常使用 解决方法: 安装System.Drawing.Common的NuGet就能正常使用了 操作之后: 这个是.netcoe中的解决办法,.net framework解决方案中添 ...
- LDAP相关操作注意事项
lc.Modify(entry.DN, new LdapModification(LdapModification.REPLACE, new LdapAttribute("mDBUseDef ...
- SharePoint2016 母版页引用样式和脚本路径无效
直接引用16目录(/_layouts/16/)会导致页面找不到文件,必须将16目录改为15目录(/_layouts/15/),估计是内部机制还没有更新,这个坑不知道要多久才会填上=,=
- 使用工具自动生成Linq类文件
第一部:运行cmd. 执行命令 cd C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.5.1 Tools 第二步:执行 ...