//
// ViewController2.swift
// swift_helloword
//
// Created by Charlie on 15/7/13.
// Copyright (c) 2015年 Json. All rights reserved.
// import Foundation
import UIKit class RootViewController: UIViewController,UITableViewDataSource,UITableViewDelegate { //协议 var tableView :UITableView? = UITableView( frame: CGRectZero, style: UITableViewStyle.Plain); override func viewDidLoad() {
configUI()
}
func configUI(){
tableView!.frame = CGRect (x: , y: , width: , height: )
self.view.addSubview(tableView!)
tableView!.delegate = self
tableView!.dataSource = self //设置代理 }
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return
}
func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
var view:UIView = UIView (frame: CGRect (x: , y: , width: , height: ))
var la = UILabel (frame: view.frame);
la.backgroundColor = UIColor.greenColor()
la.text = "第\(section)+分区" //分区的名字
view.addSubview(la)
return view;
}
func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return ; //每一个分组的高度
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cellId:String = "id"
var cell = tableView.dequeueReusableCellWithIdentifier(cellId) as? UITableViewCell; //?是可选的 就是可能是nil
if cell == nil {
cell = UITableViewCell (style: UITableViewCellStyle.Default, reuseIdentifier: cellId)
}
cell?.textLabel?.text = String (indexPath.row )
return cell!// 返回cell 或者 nil
}
}

 

swift 创建tableView并实现协议的更多相关文章

  1. swift 创建tableView 并实现协议

    import UIKit class ViewController2: UIViewController,UITableViewDelegate,UITableViewDataSource{      ...

  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. 【Android】Fragment如何获取子Fragment

    今天搞了个嵌套的Fragment,通过外部的Fragment获取的子Fragment代码: this.navigationBar = (HXKJCargoNavigationView) getFrag ...

  2. Cordova了解

    概述 Cordova让我们可以使用HTML.JS以及CSS开发跨平台App的公共部分(整个App就是一个WebView或者或者嵌入到本地组件中),与原生API的交互通过Cordova插件实现. 安装配 ...

  3. mysql学习(十一)嵌套查询 排序 分组

    select * from products where id in(select id from cats where name like '%java%');//查找类型中名字中包含java的的商 ...

  4. 【转】Mysql 根据时间戳按年月日分组统计

    create_time时间格式 SELECT DATE_FORMAT(create_time,'%Y%u') weeks,COUNT(id) COUNT FROM role GROUP BY week ...

  5. Camera实现预览、拍照

    1.利用Intent方法实现拍照并保存 在菜单或按钮的选择操作中调用如下代码,开启系统自带Camera APP,并传递一个拍照存储的路径给系统应用程序,具体如下: imgPath = "/s ...

  6. SQL Server 空间监测

    数据库文件型: select * from sys.dm_db_file_space_usage;      go                                           ...

  7. Realview MDK 中不用手动开中断的原因

    startup.s启动代码文件: ; Enter Supervisor Mode and set its Stack Pointer MSR CPSR_c, #Mode_SVC:OR:I_Bit:OR ...

  8. Mindjet 一打开鼠标就动不了解决方法

    在网上查找了一下相关资料,这个主要是Mindjet不支持64位系统造成的,其实就和Windows tablet pc input 这个服务相冲突造成的,临时的解决方法是,win+r (别告诉我你不知道 ...

  9. 利用代码改变世界 #AzureDev

    毫无疑问,开发人员是 //build/ 2013 的主角.开发人员是我们这个行业的心脏和灵魂,我们很感谢他们所做的一切.在 Satya Nadella 走上讲台发表第 2 天的主题演讲之前,我们播放了 ...

  10. 使用kd-tree加速k-means

    0.目录 前置知识 思路介绍 详述 1 确定h的中心点 2 算法步骤 java实现 1.前置知识 本文内容基于<Accelerating exact k-means algorithms wit ...