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 并实现协议的更多相关文章

  1. swift 创建tableView并实现协议

    // // ViewController2.swift // swift_helloword // // Created by Charlie on 15/7/13. // Copyright (c) ...

  2. swift - 快速代码块 - 创建 tableview等一些控件 基本属性

    1.创建tableview private lazy var cellId = "cellId" fileprivate lazy var tv : UITableView = { ...

  3. swift:创建表格UITableView

    用swift创建单元格和用iOS创建单元格形式基本相同,就是语法上有些异样.swift中调用成员方法不再使用[ ]来发送消息,而是使用.成员方法的形式调用成员函数.这种格式非常类似于java中的点成员 ...

  4. 使用OC和swift创建系统自带的刷新界面

    使用OC和swift创建系统自带的刷新界面 一:swift刷新界面代码: import UIKit class ViewController: UITableViewController { // 用 ...

  5. swift学习 - tableView自适应高度2(SnapKit Layout)

    SnapKit是Swift中自动布局的框架,相当于Objective-C中的Masonry 下面是tableView自定义cell,使用SnapKit布局的效果图: 详细代码如下: TYCustomC ...

  6. OC与Swift创建pod

    Cocoa pods 是iOS最常用的类库管理工具   OC的使用   删除源   sudo gem sources -r https://rubygems.org/ 添加源(使用淘宝的镜像,记住要用 ...

  7. swift是面向对象、面向协议、高阶类型、灵活扩展、函数式编程语言

    swift是面向对象.面向协议.高阶类型.灵活扩展.函数式编程语言

  8. 使用 Realm 和 Swift 创建 ToDo 应用

    原文出处: HOSSAM GHAREEB   译文出处:Prayer’s blog(@EclipsePrayer) 智能手机的快速发展的同时,涌现出了很多对开发者友好的开发工具,这些工具不仅使得开发变 ...

  9. [译] 用 Swift 创建自定义的键盘

    本文翻译自 How to make a custom keyboard in iOS 8 using Swift 我将讲解一些关于键盘扩展的基本知识,然后使用iOS 8 提供的新应用扩展API来创建一 ...

随机推荐

  1. ASP.NET实现年月日三级联动(局部刷新)

    直接上代码,不多说别的了 <asp:ScriptManager ID="ScriptManager1" runat="server"> </a ...

  2. Spring.net--很棒的事务处理

    1--Case 比如t_Order订单表1,t_OrderDetail订单明细表2 下一张订单会往表1插入一条数据,表2会插入多行数据 使用Spring.net事务管理 例如 ---Order---订 ...

  3. 让 IE 支持HTML5 placeholder

    HTML5 新增的placeholder属性已经得到现代浏览器的支持,旨在提供简单的API可以为文本输入框设置 描述输入字段预期值的提示信息(hint). 这是W3C在标准化的过程中对用户体验的更多考 ...

  4. [转]在 SQL Server 2008 中新建用户登录并指定该用户的数据库

    提要:我在 SQL Server 中新建用户登录时,出现了三种错误,错误代码分别是 18456.15128.4064 -----------------------------------  正 文 ...

  5. 昨天mac更新后,网络又出问题了。。。

    情况如图...

  6. 关于Aspose对于Word操作的一些扩展及思考

    Aspose.word Aspose.Words是一款先进的类库,通过它可以直接在各个应用程序中执行各种文档处理任务.Aspose.Words支持DOC,OOXML,RTF,HTML,OpenDocu ...

  7. sql server备份相关

    本文转载自http://dreamfire.blog.51cto.com/418026/152075/ 感谢作者的分享!!   数据库没有备份---应如何还原丢失的数据   环境描述: 某公司装了一台 ...

  8. sql查询语句心得

    1)where 有多个用in ,一个用= 2)自身链接 select A.Sno from S A,S B where A.Sname='a' AND A.City=B.City)) 3)外链接(同时 ...

  9. java rmi 使用方法

    server package Server; import java.rmi.Naming; import java.rmi.RMISecurityManager; import java.rmi.r ...

  10. jquery的节点查询

    jQuery.parent(expr)           //找父元素 jQuery.parents(expr)          //找到所有祖先元素,不限于父元素 jQuery.children ...