大佬教程收集整理的这篇文章主要介绍了swift3.0-第一篇tableView,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
最近这个月估计要一直设计新的项目天天开会苦不堪言啊~ 新的项目要用swift来写,从零开始还是很有乐趣的,简单总结了下table的使用,一起学习下吧。
直接上代码了
<span style="font-family:Microsoft YaHei;font-size:14px;color:#3366ff;">// // ViewController.swift // SwiftTable // // Created by a111 on 16/10/19. // Copyright © 2016年 司小文. All rights reserved. // // MARK: - import UIKit var kSize=UIScreen.main.bounds; var dataTable:UITableView! var itemStringArr=["企划部","软件部","咨询部","人事部","后勤部","产品部"] class ViewController: UIViewController,UITableViewDatasource,UITableViewDelegate { override func viewDidLoad() { super.viewDidLoad() //调用table方法 makeTable() // Do any additional setup after loading the view,typically from a nib. } // MARK: -table func makeTable (){ dataTable=UITableView.init(frame: CGRect(x: 0.0,y: 64,width: kSize.width,height: kSize.height-64),style:.plain) dataTable.delegate=self;//实现代理 dataTable.datasource=self;//实现数据源 dataTable.showsVerticalScrollInDicator = false dataTable.showsHorizontalScrollInDicator = false self.view.addSubview(dataTablE) //tableFooter dataTable.tableFooterView = UIView.init() } // MARK: -table代理 //段数 private func numberOfSectionsInTableView(tableView: UITableView) -> Int { return 1; } //行数 func tableView(_ tableView: UITableView,numberOfRowsInSection section: int) -> Int { return itemStringArr.count } //行高 private func tableView(tableView: UITableView,heightForRowATindexPath indexPath: IndexPath) -> CGFloat{ return 80 } //头部高度 private func tableView(tableView: UITableView,heightForHeaderInSection section: int) -> CGFloat { return 0.01 } //底部高度 private func tableView(tableView: UITableView,heightForFooterInSection section: int) -> CGFloat { return 0.01 } //cell func tableView(_ tableView: UITableView,cellForRowAt indexPath: IndexPath) -> UITableViewCell { let identifier="identtifier"; var cell=tableView.dequeueReusableCell(withIdentifier: identifier) if(cell == nil){ cell=UITableViewCell(style: UITableViewCellStyle.value1,reusEIDentifier: identifier); } cell?.textLabel?.text = itemStringArr[indexPath.row]; cell?.detailTextLabel?.text = "待添加内容"; cell?.detailTextLabel?.font = UIFont .systemFont(ofSize: CGFloat(13)) cell?.accessoryType=UITableViewCellAccessoryType.disclosureInDicator return cell! } //选中cell时触发这个代理 public func tableView(_ tableView: UITableView,didSELEctRowAt indexPath: IndexPath){ print("indexPath.row = SELEctRow第\(indexPath.row)行") } //取消选中cell时,触发这个代理 public func tableView(_ tableView: UITableView,didDeSELEctRowAt indexPath: IndexPath){ print("indexPath.row = DeSELEctRow第\(indexPath.row)行") } //允许编辑cell func tableView(_ tableView: UITableView,canEditRowAt indexPath: IndexPath) -> Bool { return true } //右滑触发删除按钮 func tableView(_ tableView: UITableView,ediTingStyleForRowAt indexPath: IndexPath) -> UITableViewCellEdiTingStyle { return UITableViewCellEdiTingStyle.init(rawValue: 1)! } //点击删除cell时触发 func tableView(_ tableView: UITableView,commit ediTingStyle: UITableViewCellEdiTingStyle,forRowAt indexPath: IndexPath) { print("indexPath.row = ediTingStyle第\(indexPath.row)行") } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } } </span>
感谢观看,学以致用更感谢哦~
以上是大佬教程为你收集整理的swift3.0-第一篇tableView全部内容,希望文章能够帮你解决swift3.0-第一篇tableView所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。