代码如下:

//
// 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. 接口测试基础——fiddler抓包常见问题

    fiddler抓包工作原理: 以web代理服务器的形式进行工作的,使用的代理地址是:127.0.0.1,端口默认为8888,过程如下:web代理就是在客户端和服务器之间设置一道关卡,客户端先将请求数据 ...

  2. 批量删除当前文件夹下面的.svn文件夹

    for /r . %%a in (.) do @if exist "%%a\.svn" rd /s /q "%%a\.svn 使用方法: 新建text文档,复制上面的文本 ...

  3. Celery无法注册任务的几种情况

    Celery处理异步任务使得程序不必等待任务结束就可以继续执行其它任务或返回数据结果, 在处理耗时任务如发送邮件.发送信息验证码等场景下非常适用! Celery使用方法灵活,根据具体业务有不同的部署和 ...

  4. web 部署专题(六):nginx 安装(二) linux

    https://www.cnblogs.com/quzq/p/12131696.html 基础篇 一.环境 服务器版本:CentOS 7.2 为了保证学习阶段不遇到奇怪的事情,请保证以下四点(大神选择 ...

  5. python 面向对象专题(八):特殊方法 (一)__get__、__set__、__delete__ 描述符(一)

    https://www.cnblogs.com/flashBoxer/p/9771797.html 实现了 __get__.__set__ 或 __delete__ 方法的类是描述符.描述符的用法是, ...

  6. Python模块04/包/logging日志

    Python模块04/包/logging日志 目录 Python模块04/包/logging日志 内容大纲 1.包 2.logging日志 3.今日总结 内容大纲 1.包 2.logging日志 1. ...

  7. Python函数03/函数名的第一类对象及使用/f 格式化/迭代器/递归

    Python函数03/函数名的第一类对象及使用/f 格式化/迭代器/递归 目录 Python函数03/函数名的第一类对象及使用/f 格式化/迭代器/递归 内容纲要 1.函数名的第一类对象及使用 2.f ...

  8. P1136 迎接仪式 题解

    题目描述 LHX教主要来X市指导OI学习工作了.为了迎接教主,在一条道路旁,一群Orz教主er穿着文化衫站在道路两旁迎接教主,每件文化衫上都印着大字.一旁的Orzer依次摆出"欢迎欢迎欢迎欢 ...

  9. row_number() over()排序功能说明

    1.row_number() over()排序功能: (1) row_number() over()分组排序功能: 在使用 row_number() over()函数时候,over()里头的分组以及排 ...

  10. 盘点JMeter不为人知那一些细节

    Jmeter工作原理 向服务器提交请求,并从服务器取回请求返回的结果.即建立一个线程池,多线程运行取样器产生大量负载,在运行过程中通过断言来验证结果的正确性,通过监听器来记录测试结果. 文章内容以Jm ...