代码如下:

//
// ViewController.swift
// demo1_tableview
//
// Created by Alice_ss on 2018/2/24.
// Copyright © 2018年 AC. All rights reserved.
// import UIKit class ViewController: UIViewController,UITableViewDelegate,UITableViewDataSource{ //定义一个tableview
var tableview :UITableView? override func viewDidLoad() {
super.viewDidLoad()
self.tableview = UITableView.init(frame: self.view.frame, style: UITableViewStyle.plain)
self.tableview?.delegate = self
self.tableview?.dataSource = self
self.view .addSubview(self.tableview!) } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
var cell = tableview?.dequeueReusableCell(withIdentifier: "cellID")
if cell == nil {
cell = UITableViewCell.init(style: UITableViewCellStyle.default, reuseIdentifier: "cellID")
}
cell?.textLabel?.text = String(indexPath.row)
return cell! }
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 10
}
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
var headerView = UIView.init(frame: CGRect.init(x: 0, y: 0, width: UIScreen.main.bounds.size.width, height: <#T##CGFloat#>))
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
} }

刚开始看swift项目

坐下笔记:

创建一个简单的tablecview项目,就像是上述代码就可以完成了。

遇到的问题:

1.添加代理的时候老是报错。后来经过百度,在下边的方法中 定义变量的时候在变量的后边加上? 报错就消失了。但是在使用的时候需要加上一个!才能进行。

2.其他的跟oc很类似,就不多介绍了。

swift demo1 tableview的更多相关文章

  1. swift学习 - tableView自适应高度2(SnapKit Layout)

    SnapKit是Swift中自动布局的框架,相当于Objective-C中的Masonry 下面是tableView自定义cell,使用SnapKit布局的效果图: 详细代码如下: TYCustomC ...

  2. swift 创建tableView并实现协议

    // // ViewController2.swift // swift_helloword // // Created by Charlie on 15/7/13. // Copyright (c) ...

  3. Swift - 使用TableView的静态单元格进行页面布局

    通过使用静态单元格的列表,我们可以很方便的进行页面布局.下面通过一个“添加任务页面”来进行演示. 效果图如下: 实现步骤: 1,在storyboard中拖入一个TableViewController, ...

  4. Swift初窥--使用Swift实现TableView

    完毕Swift的语法关之后.来点实际的Task,第一个任务是写一个tableview,使用cocoaTouch里tableview这个经常使用的控件. 创建project.选择Swift语言 首先是用 ...

  5. swift中tableview的使用和注意事项

    今天使用swift写了个简单的tableView,语法和用法上跟oc没多大的区别.但是还是有一些细节的地方需要注意一下的. 先上代码 import UIKit class ViewController ...

  6. Swift - 设置tableView每个分区cell圆角

    1.// 重新绘制cell边框 func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRow ...

  7. swift 创建tableView 并实现协议

    import UIKit class ViewController2: UIViewController,UITableViewDelegate,UITableViewDataSource{      ...

  8. swift学习 - tableView自适应高度1(xib autoLayout)

    tableView自适应高度 效果图: 源码: class ViewController: UIViewController,UITableViewDelegate,UITableViewDataSo ...

  9. swift 分组tableview 设置分区投或者尾部,隐藏默认间隔高度

    1.隐藏尾部或者头部,配套使用 //注册头部id tv.register(JYWithdrawalRecordSectionView.self, forHeaderFooterViewReuseIde ...

随机推荐

  1. js复制内容到剪贴板格式化粘贴到excel中

    <input id="Button1" type="button" value="导出EXCEL" onclick="cop ...

  2. python面试题五:Python 编程

    1.B Tree和B+ Tree的区别? 1.B树中同一键值不会出现多次,并且有可能出现在叶结点,也有可能出现在非叶结点中. 而B+树的键一定会出现在叶结点中,并有可能在非叶结点中重复出现,以维持B+ ...

  3. 微信小程序 + wepy快速开发

    wepy官网:https://tencent.github.io/wepy/document.html,想要了解全面最好去官网,以下只是指出项目里常用地方. 1.页面跳转 (1)//有返回跳转wepy ...

  4. bzoj3732Network

    bzoj3732Network 题意: 给一个无向图,k个询问求节点a到节点b最长边的最小值.n,k≤15000. 题解: ”最长边的最小值“经常可以用最小生成树解决,因为生成树里的每一条边都是可取的 ...

  5. Mysql UDF提权方法

    0x01 UDF UDF(user defined function)用户自定义函数,是mysql的一个拓展接口.用户可以通过自定义函数实现在mysql中无法方便实现的功能,其添加的新函数都可以在sq ...

  6. tomcat内容总结

    tomcat的安装以及配置环境变量 1.tomcat的官网下载地址:http://tomcat.apache.org/ tomcat有很多版本,有解压版 和 安装版,还分windows (还分为32位 ...

  7. js 对象数组根据某个名称删除数组中的对象

    delArrayItem: function (array,item) { const index = array.findIndex(text => text.name === item.na ...

  8. webpack源码-loader的原理

    版本 webpack :"version": "3.12.0", webpack配置中的loaders配置是如何传递的 webpack/lib/NormalMo ...

  9. javascript兼容性:展开运算符 ... 的降级

    展开运算符 ... 是一个很好用的ES6新特性,用的好的话,可以节约很多代码. 但是作为ES6特性,它有兼容性问题,而且Babal(在线转码网页)并不会转换展开运算符. 展开运算符大体分为两种用法:展 ...

  10. 设计模式:memento模式

    目的:在不破坏系统封装性的前提下,记录系统每一步的状态,可以做到状态回退和前进 方法: 定义一个数据类,保存所有相关数据 定义一个管理类,提供保存和恢复的接口 具体操作类调用管理类的保存和恢复接口 例 ...