//
// 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. WindowsForm 计算器

             计算器  可以分一下类 数字键 + - * / % =和撤销 归零C最简单 下面看一下计算器具体的代码 using System; using System.Collections. ...

  2. WebService到底是什么

    WebService到底是什么 http://blog.csdn.net/wooshn/article/details/8069087 张孝祥WebService  http://wenku.baid ...

  3. const与重载

    转载自CSDN博客:http://blog.csdn.net/polarbearboy/article/details/6762752   (由于该作者也属于转载,不知原出处) PS:我们很易对下面这 ...

  4. python学习笔记:python数字

    一.数字类型分类 数字提供了标量存储和直接访问,它是不可更改类型,也就是说变更数字的值会产生新的对象.python的对象模型与常规对象模型有些不同,对数字对象的更新,实际上是生成了一个新的数值对象,并 ...

  5. linux下的gdb调试工具--断点调试

    到目前为止我们的调试手段只有一种: 根据程序执行时的出错现象假设错误原因,然后在代码中适当的位置插入printf,执行程序并分析打印结果,如果结果和预期的一样,就基本上证明了自己假设的错误原因,就可以 ...

  6. eclipse 和myEclipse 项目导入

    经常在eclipse/myeclipse中导入web项目时,出现转不了项目类型的问题,导入后就是一个java项目. 有两种情况: 一.eclipse无法识别其他eclipse的web项目 解决步骤: ...

  7. 浅析document.createDocumentFragment()与js效率

    对于循环批量操作页面的DOM有很大帮助!利用文档碎片处理,然后一次性append,并且使用原生的javascript语句操作 document.createDocumentFragment()说白了就 ...

  8. OleVariant的本质

    OleVariant的本质 OleVariant,COM的一种数据类型.MIDAS基于COM之上构建的,自然使用OleVariant作为数据序列格式. 延续到现在最新的DATASNAP仍然支持它. T ...

  9. docker 容器管理常用命令

    Docker 容器管理: docker create -it centos //这样可以创建一个容器,但该容器并没有启动: create Create a new container 创建一个容器: ...

  10. CM_RESOURCE_LIST structure

    The CM_RESOURCE_LIST structure specifies all of the system hardware resources assigned to a device. ...