Swift学习之--TableView的基本使用
来源:互联网 发布:java 向邮箱发送邮件 编辑:程序博客网 时间:2024/06/06 04:55
每个iOS开发人员都知道tableview,因为它是我们开发中最常用的Contrller了.下面就简单介绍Swift中tableview的一些简单的使用:
(先看效果图)
下面直接贴代码
class ViewController: UIViewController{ override func loadView() { let tv = UITableView() tv.frame = UIScreen.mainScreen().bounds tv.dataSource = self tv.delegate = self tv.separatorColor = UIColor.lightGrayColor() view = tv } override func viewDidLoad() { //修改导航栏背景色 navigationController?.navigationBar.barTintColor = UIColor(red: 55/255, green: 186/255, blue: 89/255, alpha: 1) //修改导航栏文字颜色 navigationController?.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName: UIColor.whiteColor()] //修改导航栏按钮颜色 navigationController?.navigationBar.tintColor = UIColor.whiteColor() //添加标题 navigationItem.title = "TableView基本使用" //修改导航栏背景图片// navigationController?.navigationBar.setBackgroundImage(UIImage(named: "bg5"), forBarMetrics: .Default) } // MARK:- // MARK:-懒加载数据 lazy var dataList:[String] = { return ["rookic","yx","toxic","mine"] }()}// MARK:-// MARK:- 苹果官方建议, 可以将数据源代理方法单独写到一个扩展中,以便提高代码的可读性// extension 相当于OC中的 catogoryextension ViewController:UITableViewDelegate,UITableViewDataSource{ // MARK:- // MARK:-UITableViewDataSource // 共多少行 func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return dataList.count } // 每行显示什么内容 func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { let str = "cellID" // 1 取出cell var cell = tableView.dequeueReusableCellWithIdentifier(str) if cell == nil { cell = UITableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: str) } // 2 设置数据 cell?.textLabel?.text = dataList[indexPath.row] cell?.textLabel?.textColor = UIColor.redColor() // 3 返回cell return cell! }}
新博客地址
1 0
- Swift学习之--TableView的基本使用
- swift- tableView 的使用
- Swift学习记录 -- 15.tableView的创建与基本操作
- swift中tableview的使用
- TableView的基本使用
- tableView的基本使用
- Swift 学习之集合的基本用法
- iOS TableView的基本使用
- swift之异步加载图片的tableview
- swift中tableview的使用和注意事项
- Swift中tableView的建立与使用
- swift入门之TableView
- iOS TableView 使用(swift)
- swift-tableview使用
- Swift学习之基本语法
- JavaFX之TableView的使用
- 1、swift学习-字典的基本使用
- Swift学习记录 -- 6. 字符串的基本使用
- Android网络编程基础简介
- IOS开发之新浪围脖
- Badgeview
- Hibernate 数据的批量插入、更新和删除
- 欢迎使用CSDN-markdown编辑器
- Swift学习之--TableView的基本使用
- 唯一性标识的生成策略
- 正则表达式使用方法(补充)
- linux进程间通信
- 底层解惑-jndi与数据库连接池的联系与区别
- iOS开发之新浪微博山寨版代码优化
- Linux下C语言实现LCD屏幕截图
- IETF HTTP 规范概览
- 课程练习三-1009-problem I