swift 创建tableView 并实现协议
import UIKit
class ViewController2: UIViewController,UITableViewDelegate,UITableViewDataSource{
override func viewDidLoad() {
super.viewDidLoad()
self.view.backgroundColor=UIColor.orangeColor()
var myTableView = UITableView(frame: CGRectMake(0, 0, UIScreen .mainScreen().bounds.size.width, UIScreen.mainScreen().bounds.size.height), style: UITableViewStyle.Plain)
self.view.addSubview(myTableView)
myTableView.delegate = self
myTableView.dataSource = self
myTableView.backgroundColor = UIColor.whiteColor()
}
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 10
}
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return 60
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell = UITableViewCell()
cell.textLabel?.text = "MyFirstSwift"
cell.detailTextLabel?.text = "gaga"
if indexPath.row%2 == 0{
cell.imageView?
.image = UIImage(named: "image1")
}else{
cell.imageView?
.image = UIImage(named: "image2")
}
return cell
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}
swift 创建tableView 并实现协议的更多相关文章
- swift 创建tableView并实现协议
// // ViewController2.swift // swift_helloword // // Created by Charlie on 15/7/13. // Copyright (c) ...
- swift - 快速代码块 - 创建 tableview等一些控件 基本属性
1.创建tableview private lazy var cellId = "cellId" fileprivate lazy var tv : UITableView = { ...
- swift:创建表格UITableView
用swift创建单元格和用iOS创建单元格形式基本相同,就是语法上有些异样.swift中调用成员方法不再使用[ ]来发送消息,而是使用.成员方法的形式调用成员函数.这种格式非常类似于java中的点成员 ...
- 使用OC和swift创建系统自带的刷新界面
使用OC和swift创建系统自带的刷新界面 一:swift刷新界面代码: import UIKit class ViewController: UITableViewController { // 用 ...
- swift学习 - tableView自适应高度2(SnapKit Layout)
SnapKit是Swift中自动布局的框架,相当于Objective-C中的Masonry 下面是tableView自定义cell,使用SnapKit布局的效果图: 详细代码如下: TYCustomC ...
- OC与Swift创建pod
Cocoa pods 是iOS最常用的类库管理工具 OC的使用 删除源 sudo gem sources -r https://rubygems.org/ 添加源(使用淘宝的镜像,记住要用 ...
- swift是面向对象、面向协议、高阶类型、灵活扩展、函数式编程语言
swift是面向对象.面向协议.高阶类型.灵活扩展.函数式编程语言
- 使用 Realm 和 Swift 创建 ToDo 应用
原文出处: HOSSAM GHAREEB 译文出处:Prayer’s blog(@EclipsePrayer) 智能手机的快速发展的同时,涌现出了很多对开发者友好的开发工具,这些工具不仅使得开发变 ...
- [译] 用 Swift 创建自定义的键盘
本文翻译自 How to make a custom keyboard in iOS 8 using Swift 我将讲解一些关于键盘扩展的基本知识,然后使用iOS 8 提供的新应用扩展API来创建一 ...
随机推荐
- maven第5章坐标和依赖
5.5依赖范围 runtime:运行时依赖范围 举的例子是JDBC驱动实现,不理解? 编译的时候只需要引入jdk提供的jdbc类和方法,比如java.sql.*;这时编译没有报错,但是没有引入mysq ...
- AD域属性对照表
查看文章 AD属性对照表(一)[AD域][属性] 2011年08月25日 星期四 19:36AD属性对照表家庭电话 :“常规”标签 姓 Sn Y 名 gi ...
- 仿写Windows7桌面和任务栏 HTML5+CSS3+Jquery实现
过去一段时间零零散散的自学了一点点jquery的相关用法,基本上属于用到哪个了,就去查然后就学一点,没有系统的学过,深入的用法也不是特别了解,毕竟javascript基础就比较薄弱.经过一段时间的零敲 ...
- String在JAVA里是固定长度的吗?为什么可用“+”连接
所谓长度固定不是你理解的意思而是说String类中存储的char[]是final的,不能修改,你对String的操作实际上是产生了一个新的String,对于某一个String来说,长度就是固定的了 S ...
- Win8节省C盘空间攻略
问题分析: 1.系统页面文件(虚拟内存)占用空间 2.自动更新的缓存文件 3.系统保护的备份文件(系统还原用的) 4.休眠文件 5.索引文件 6.桌面文件 解决办法: 1.机器是8G内存,完全不需要虚 ...
- 一些SQL语句的问题
1.getdate()函数问题 go create table table_1( id int primary key identity, name ) not null, daytime datet ...
- html5中的一些小知识点(CSS)
1.点击a标签周围区域就可以进入超链接: a标签 的css样式中的 display属性设置为block 就可以了 2.文字左右居中: text-align 属性值为 center 3.文字上下居中: ...
- 记一次 nginx 504 Gateway Time-out
今天程序在执行一项excel导出任务的时候 出现了nginx超时的提示 nginx 504 Gateway Time-out 排查过程: 查看该任务 发现内容是一个数据量20000条信息 每条信息有5 ...
- 最完美的匹配网页中图片 src 部分的正则表达式
$str='<p style="padding: 0px; margin-top: 0px; margin-bottom: 0px; line-height: 200%;"& ...
- Python 改变当前工作目录
在shell里编辑: import os os.getcwd() #取得当前工作目录 os.chdir(r'目标目录') # os.chdir(r'd:\learnpy')