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. linux执行文件命令

    1.如果path中有你的程序所在的目录,那么直接执行filename即可 2.如果path中没有程序所在目录,那么进入目录./filename或者path/filename 比如 wj@ubuntu: ...

  2. (转)jquery.validator规则

      登录|注册     收藏成功 确定 收藏失败,请重新收藏 确定 标题 标题不能为空 网址 标签 摘要   公开 取消收藏             分享资讯 传PPT/文档 提问题 写博客 传资源 ...

  3. (转)linux下导入、导出mysql数据库命令

    原文链接:http://www.xiaohuai.com/2902 一.导出数据库用mysqldump命令(注意mysql的安装路径,即此命令的路径):1.导出数据和表结构:mysqldump -u用 ...

  4. 数据转换错误,java.lang.NumberFormatException: null

    今天写项目时报了一个数组转换错误的异常,让我找了半天5555 -_- . 一般出现这种错误呢,情况都是parseInt转换所触发的,像下面这行代码 int factorOneInt = Integer ...

  5. Shell中逻辑判断

    [ 条件1 -a 条件2 ]   当1和2都真时才为真 [ 条件1 -o 条件2 ]   当1和2其中一个为真即为真 [ ! 条件 ]           取反   &&     与 ...

  6. vs2013+sql server2012 +win8.1+entity framework + linq

    项目右键添加类选择“ADO.NET实体数据模型” 选择“空……” 项目会自动产生后缀.edmx的文件(ModelTest.edmx),会自动添加引用System.Runtime.Serializati ...

  7. Struts2 处理表单重复提交

    * 在表单页面中增加一个隐藏域:<s:token></s:token>(需要在表单内)        * 创建一个struts.xml的配置文件,具体配置如下:         ...

  8. 如何启动Service,如何停用Service(转)

    如何启用Service,如何停用Service Android中的服务和windows中的服务是类似的东西,服务一般没有用户操作界面,它运行于系统中不容易被用户发现,可以使用它开发如监控之类的程序.服 ...

  9. Oracle数据库之PL/SQL过程与函数

    Oracle数据库之PL/SQL过程与函数 PL/SQL块分为匿名块与命名块,命名块又包含子程序.包和触发器. 过程和函数统称为PL/SQL子程序,我们可以将商业逻辑.企业规则写成过程或函数保存到数据 ...

  10. 添加view类图中的二级菜单

    void CFafdsafasdfasfasView::OnLButtonDown(UINT nFlags, CPoint point) { // TODO: Add your message han ...