代码如下:

//
// 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. DOM 和 BOM 区别

    DOM, DOCUMENT, BOM, WINDOW 区别DOM 是为了操作文档出现的 API,document 是其的一个对象:BOM 是为了操作浏览器出现的 API,window 是其的一个对象. ...

  2. 目录(Django开发)

    python网络编程-socket编程 Django 笔记分享 Django之[基础篇] Django之[进阶篇] Django之 url组件 Django之 Models组件 Django之 adm ...

  3. 【面试题资源共享】一文总结最高频软件测试|sq|语句|思维发散|计算机基础|Linux|测试用例|接口测试|等技术面试题

    思维发散 1.一个球, -把尺子长度是球直径的2/3,怎样测出半径?2.四枚硬币,花面朝上,每次翻转三个,几次可以将四枚硬币变为字面朝上?3. U2合唱团在1 7分钟内赶到演唱会现场问题?4.小明一家 ...

  4. 什么?你正在学web自动化测试?那这些Selenium的基本操作你了解过吗?

    在自动化测试中,我们都知道是通过定位元素来实现的,那么有时候我们定位元素定位不到是为什么呢? 1.页面出现了iframe 2.出现了新的窗口,没有实现句柄的切换 3.三种等待方式,没有选择其中之一来使 ...

  5. 什么是A站、B站、C站、D站、E站、F站、G站、HIJKLM站N站?

    A站AcFun弹幕视频网,简称“A站”,成立于2007年6月,取意于Anime Comic Fun,是中国大陆第一家弹幕视频网站.A站以视频为载体,逐步发展出基于原生内容二次创作的完整生态,拥有高质量 ...

  6. Ethical Hacking - Web Penetration Testing(10)

    SQL INJECTION SQLMAP Tool designed to exploit SQL injections. Works with many DB types, MySQL, MSSQL ...

  7. Ethical Hacking - NETWORK PENETRATION TESTING(17)

    MITM - bypassing HTTPS Most websites use https in their login pages, this means that these pages are ...

  8. react 实战:写一个年份选择器

    上代码. 组件的Js文件. import React, { Component } from "react"; import Style from './myYearSelect. ...

  9. spring读取jdbc(file方式)

    使用PropertyPlaceholderConfigurer类载入外部配置 在Spring项目中,你可能需要从properties文件中读入配置注入到bean中,例如数据库连接信息,memcache ...

  10. Mysql的复制原理以及流程

    MySQL复制概述 简单来说就是保证主服务器(Master)和从服务器(Slave)的数据是一致性的,向Master插入数据后,Slave会自动从Master把修改的数据同步过来(有一定的延迟),通过 ...