//
// 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. eclipse自动提示类型的作用

    eclipse的自动提示功能确实十分好用,但是只是笼统的都勾上了,所有会有好多重复项,看着很眼疼. 今天就稍微研究了下,略微知道了几个类型的作用: 序号 类型 大体的中文意思 作用 1 Java Ty ...

  2. Visual C++ 64bit应用程序项目设置

    Visual Studio 2005 This topic describes how to set up C++ applications to target 64-bit platforms us ...

  3. elegant 的长整数加法 string 实现

    string strAdd(string &v1, string &v2){ string res = ""; ; int len1 = v1.size(), le ...

  4. git撤销修改

    在Git中,删除也是一个修改操作,我们实战一下,先添加一个新文件test.txt到Git并且提交: $ git add test.txt $ git commit -m "add test. ...

  5. Android 关于操作UI线程

    在非UI线程里访问 Android UI toolkit—这个在一个worker线程修改了 View .这会导致不可预期的结果,而且还难以调试. 为了修复这个问题,Android提供了几个方法从非UI ...

  6. 收MUD巫师学徒,MUD开发,LPC语言开发

    收MUD巫师学徒,MUD开发,LPC语言开发 对这个有兴趣的联系我,签订协议  Q 184377367

  7. leetcode算法刷题(二)——动态规划(一)

    上次刷了五六道题,都是关于string处理的,这次想换个知识点刷一下,然后再回头刷string的题,当做复习.. 这几天主要会选择动态规划的题目,因为以前从没刷过这方面的东西,很多东西都不是很懂..就 ...

  8. J2SE知识点摘记(三)

    1.         在java只允许单继承,而不允许多重继承,也就是说一个子类只能有一个父类.但在java中却允许多层继承. 2.         非内部Class只能被public或者defaul ...

  9. modbus rtu 协议转DLT645-2007和DLT645-1997电表协议转换器定制,

    现场会碰到现场数据为Modbus协议,但是后台系统为DLT645协议系统,本模块支持将工业ModbusRtu协议转换为电表国标协议DLT645协议,支持1997和2007俩种标准,只需要进行简单的配置 ...

  10. 测试Web服务接口

    1. http://www.iteye.com/topic/142034 2. http://www.iteye.com/topic/1123835 3.http://yongguang423.ite ...