swift 创建tableView并实现协议
- //
- // 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并实现协议的更多相关文章
- swift 创建tableView 并实现协议
import UIKit class ViewController2: UIViewController,UITableViewDelegate,UITableViewDataSource{ ...
- swift - 快速代码块 - 创建 tableview等一些控件 基本属性
1.创建tableview private lazy var cellId = "cellId" fileprivate lazy var tv : UITableView = { ...
- swift:创建表格UITableView
用swift创建单元格和用iOS创建单元格形式基本相同,就是语法上有些异样.swift中调用成员方法不再使用[ ]来发送消息,而是使用.成员方法的形式调用成员函数.这种格式非常类似于java中的点成员 ...
- 使用OC和swift创建系统自带的刷新界面
使用OC和swift创建系统自带的刷新界面 一:swift刷新界面代码: import UIKit class ViewController: UITableViewController { // 用 ...
- swift学习 - tableView自适应高度2(SnapKit Layout)
SnapKit是Swift中自动布局的框架,相当于Objective-C中的Masonry 下面是tableView自定义cell,使用SnapKit布局的效果图: 详细代码如下: TYCustomC ...
- OC与Swift创建pod
Cocoa pods 是iOS最常用的类库管理工具 OC的使用 删除源 sudo gem sources -r https://rubygems.org/ 添加源(使用淘宝的镜像,记住要用 ...
- swift是面向对象、面向协议、高阶类型、灵活扩展、函数式编程语言
swift是面向对象.面向协议.高阶类型.灵活扩展.函数式编程语言
- 使用 Realm 和 Swift 创建 ToDo 应用
原文出处: HOSSAM GHAREEB 译文出处:Prayer’s blog(@EclipsePrayer) 智能手机的快速发展的同时,涌现出了很多对开发者友好的开发工具,这些工具不仅使得开发变 ...
- [译] 用 Swift 创建自定义的键盘
本文翻译自 How to make a custom keyboard in iOS 8 using Swift 我将讲解一些关于键盘扩展的基本知识,然后使用iOS 8 提供的新应用扩展API来创建一 ...
随机推荐
- Oracle的分页查询语句优化
Oracle的分页查询语句基本上可以按照本文给出的格式来进行套用. (一) 分页查询格式: SELECT * FROM ( SELECT A.*, ROWNUM RN FROM (SELECT ...
- WindowsForm界面 运行顺序 Form属性
WindowsForm界面 运行顺序 Form属性 什么是类:1 类是面向对象编程的基本单元.类包含了两个成员 字段(Field)和方法方法(Method) 2 字段即变量 方法即函数什么是字段:字段 ...
- mysql导出命令
数据库备份 /data/mysql/bin/mysqldump -hlocalhost -u'root' -p'do' my_db --single-transaction -q | gzip > ...
- 35个jQuery小技巧!
1. 禁止右键点击$(document).ready(function(){ $(document).bind("contextmenu",function(e){ ...
- Android.Hacks.01_Centering views using weights
Android.Hacks读书笔记01 #1#权重布局之解析: LinearLayout ’s android:weightSum LinearLayout ’s child android ...
- input submit button iOS webview browser diffrence
最近做项目用到了webview, 在浏览器中显示正常的input[type="submit"]按钮, 加载到webview中后css里的设置都失效了, webview里渲染的是最原 ...
- 运维人员:走好你的IT运维路
转自 http://os.51cto.com/art/201303/387120.htm 现阶段,大多数运维人员只是处于被动低效率手工救火的状态,企业对其重视程度不高,导致部分运维人员对自己的 ...
- MFC 双缓冲加载背景
首先定义DCmemDc和Bitmap CDC DCmemDc: CBitmap memBitmap; CBitmap *oldBitmap; 然后创建一个适应当前内存的DCmemDc CDC * dc ...
- Oracle字符编码
.检查服务器编码: 执行SQL语法: Java代码 select * from v$nls_parameters; 或 Java代码 select * from nls_database_parame ...
- Cortex-M3和Cortex-M4 Fault异常应用之二 ----- Fault处理函数的实现
在项目处于调试期间,Fault处理程序可能只是一个断点指令,调试器遇到这个指令后停止程序的运行.默认情况下,由于非硬Fault被禁能,所有发生的非Fault都会上访成硬Fault,因此只要在硬Faul ...