swift 创建tableView并实现协议
2024-10-16 00:51:48
//
// 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
}
}
最新文章
- [原]HAproxy 代理技术原理探究
- iOS-推送,证书申请,本地推送
- 2.0(3)MongoDB数据导入导出
- 添加css的方式:link与@import区别
- Qt Style Sheet实践(三):QCheckBox和QRadioButton
- pt-heartbeat使用实践
- Spring.Net AOP实例
- cocos2d-x创建场景
- 《Windows驱动开发技术详解》之HelloDDK
- Java数组的一些使用方法及堆栈存储
- C3垂直居中均分
- Gym101138D Strange Queries/BZOJ5016 SNOI2017 一个简单的询问 莫队、前缀和、容斥
- 查看mysql的版本号
- setAttribute的浏览器兼容性(转)
- 彻底解决:java.sql.SQLException: Incorrect string value: '\xF0\x9F\x92\x94' for column 'name' at row 1
- python全栈开发day17-常用模块collections,random,time,os,sys,序列化(json pickle shelve)
- 【HAOI2012】容易题
- AI 实验--v_JULY_v
- 在ASP.NET MVC中使用Castle Windsor
- Codeforces Round #131 Div1 B
热门文章
- js问题学习
- 在ie中用滤镜 (filter:progid:DXImageTransform.Microsoft.gradient)会触发overflow:hidden?
- 以Ajax的方式访问数据库
- php正则提取img所有属性值
- Java 集合嵌套List of List
- 行业百科知识--Github
- 欧几里得求最大公约数--JAVA递归实现
- [问题解决] LaTex Error:Unknown graphics extension:.eps
- 转载:10 Easy Steps to a Complete Understanding of SQL
- mysql排行榜sql的实现