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来创建一 ...
随机推荐
- 如何使用css、布局横向导航栏
使用css布局横向导航栏,css应用给网页样式的方式,就相当于,给人怎么去穿上衣服,不同的衣服有不同的穿法,这里我们使用的是内联式.在这里 我们可以适当的把值调的大一点,这样我们就可以很容易的对比. ...
- 利用eclipse开发php<转>
1.安装php环境 Eclipse支持PHP自动提示 其实如果你已经安装好了php环境(安装过程见)的话,只需要下面2步就可以了.hoho,很简单的. 1,下载eclipse中php的插件phpecl ...
- jQuery节点操作,jQuery插入节点,jQuery删除节点,jQuery Dom操作
一.创建节点 1 var box = $('<div>节点</div>'); //创建一个节点,或者var box = "<div>节点</div& ...
- office - 连接字符串.
Microsoft ACE OLEDB 12.0 Connect to Excel 2007 (and later) files with the Xlsx file extension. That ...
- 安装VS2010后,如何设置老版本的项目文件不是默认用VS2010打开
1.系统先后安装了VS2008和VS2010,在打开用VS2008创建的项目文件时总是会默认用VS2010打开,选择打开方式都不行,很不方便,差点要把VS2010卸载了. 其实只需要简单设置V ...
- dom方法读取xml(不常用)
Book.java package com.xml.demo; public class Book { private int id; private String name; private Flo ...
- startActivityForResult
Activity提供了startActivityForResult(Intent intent, int requestCode)方法打开新的Activity,新的Activity关闭后会向前面的Ac ...
- .net概述1
1.什么是.net 首先我先说说这个词的读音,很多外行朋友读作"点net"甚至许多圈内朋友也这样读,其实它正确读法应该是读作"dot net",音译即为&quo ...
- Ubuntu下搭建本地WordPress站点
想在本地搭建WordPress博客站点作测试用?本教程一步一步教您在Linux上搭建一个LAMP(Linux, Apache, MySQL, PHP)服务器并部署WordPress博客. 请注意在复制 ...
- DOS头 IMAGE_DOS_HEADER
IMAGE_DOS_HEADER STRUCT { +0h WORD e_magic // Magic DOS signature MZ(4Dh 5Ah) DOS可执行文件标记 +2h WORD e_ ...