swift demo1 tableview
代码如下:
//
// 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的更多相关文章
- swift学习 - tableView自适应高度2(SnapKit Layout)
SnapKit是Swift中自动布局的框架,相当于Objective-C中的Masonry 下面是tableView自定义cell,使用SnapKit布局的效果图: 详细代码如下: TYCustomC ...
- swift 创建tableView并实现协议
// // ViewController2.swift // swift_helloword // // Created by Charlie on 15/7/13. // Copyright (c) ...
- Swift - 使用TableView的静态单元格进行页面布局
通过使用静态单元格的列表,我们可以很方便的进行页面布局.下面通过一个“添加任务页面”来进行演示. 效果图如下: 实现步骤: 1,在storyboard中拖入一个TableViewController, ...
- Swift初窥--使用Swift实现TableView
完毕Swift的语法关之后.来点实际的Task,第一个任务是写一个tableview,使用cocoaTouch里tableview这个经常使用的控件. 创建project.选择Swift语言 首先是用 ...
- swift中tableview的使用和注意事项
今天使用swift写了个简单的tableView,语法和用法上跟oc没多大的区别.但是还是有一些细节的地方需要注意一下的. 先上代码 import UIKit class ViewController ...
- Swift - 设置tableView每个分区cell圆角
1.// 重新绘制cell边框 func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRow ...
- swift 创建tableView 并实现协议
import UIKit class ViewController2: UIViewController,UITableViewDelegate,UITableViewDataSource{ ...
- swift学习 - tableView自适应高度1(xib autoLayout)
tableView自适应高度 效果图: 源码: class ViewController: UIViewController,UITableViewDelegate,UITableViewDataSo ...
- swift 分组tableview 设置分区投或者尾部,隐藏默认间隔高度
1.隐藏尾部或者头部,配套使用 //注册头部id tv.register(JYWithdrawalRecordSectionView.self, forHeaderFooterViewReuseIde ...
随机推荐
- SQLserver , MySQL的区别和各自的一些简单方法案列
SQL Server数据库和MySQL数据库有什么区别呢?今天我们来分析一下这两种数据库的不同之处以及这两种数据库的一些简单用途:SQL Server数据库和MySQL数据库有什么区别: 对于程序开发 ...
- day38 作业
实现并发的里两种方式 # 第一种 from multiprocessing import Process import time class MyProcess(Process): def run(s ...
- Mysql基础(十):MYSQL中使用事务的案例
https://www.cnblogs.com/lsqbk/p/10145306.html 基本介绍 事务用于保证数据的一致性,它由一组相关的dml语句组成,该组的dml语句要么全部成功,要么全部失败 ...
- 01-flask旅行网系统功能设计
应用flask框架实现一个介绍旅游景区及旅游攻略的网站,一个旅行网包括前台和后台两部分,前台部分用户使用,后台部分管理员使用,系统开发坏境如下: 虚拟环境:virtualenv 数据库:MySQL 开 ...
- 《Head First 设计模式》:装饰者模式
正文 一.定义 装饰者模式动态地将责任(功能)附加到对象上.若要扩展功能,装饰者提供了比继承更有弹性的替代方案. 要点: 装饰者和被装饰者有相同的超类型. 可以用一个或多个装饰者包装一个对象. 既然装 ...
- Active Directory - Creating users via PowerShell
Method1: Create a user by executing the following PowerShell Script. New-ADUser -name 'Michael Jorda ...
- webpack源码-打包资源输出到本地
webpack收集完依赖是怎么打包资源的呢? 入口compiler.js: this.applyPluginsParallel("make", compilation, err = ...
- 使用 Github Actions 自动部署 Angular 应用到 Github Pages
前言 最近在学习 Angular,一些基础的语法也学习的差不多了,就在 github 上新建了一个代码仓库,准备用 ng-zorro 搭个后台应用的模板,方便自己以后写些小东西时可以直接使用.前端项目 ...
- C++语法小记---智能指针
智能指针 用于缓解内存泄露的问题 用于替代原生指针 军规:只能指向堆空间中的对象或变量 方法 在智能指针的析构函数中调用delete 重载"->"操作符,只能重载成成员函数, ...
- 题解 洛谷 P4547 【[THUWC2017]随机二分图】
根据题意,题目中所求的即为所有\(n!\)种完美匹配的各自的出现概率之和再乘上\(2^n\)的值. 发现\(n\)很小,考虑状压\(DP\).设\(f_{S,T}\)为左部图匹配情况为\(S\),右部 ...