1. import UIKit
  2.  
  3. @UIApplicationMain
  4. class AppDelegate: UIResponder, UIApplicationDelegate {
  5.  
  6. var window: UIWindow?
  7.  
  8. func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
  9. self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
  10. // Override point for customization after application launch.
  11. self.window!.backgroundColor = UIColor.whiteColor()
  12.  
  13. let navigation = UINavigationController(rootViewController: RootViewController())
  14. self.window?.rootViewController = navigation
  15.  
  16. self.window!.makeKeyAndVisible()
  17. return true
  18. }
  19.  
  20. }
  1. import UIKit
  2.  
  3. class RootViewController: UIViewController {
  4.  
  5. override func loadView() {
  6. super.loadView()
  7. //初始化UITableView
  8. let tableView = UITableView()
  9. tableView.frame = UIScreen.mainScreen().bounds
  10. tableView.dataSource = self
  11. tableView.delegate = self
  12. self.view.addSubview(tableView)
  13. }
  14. //懒加载数据
  15. lazy var datas:[String] = {
  16. return ["是雨是泪","分分钟需要你","伤心太平洋","曾经最痛","飘雪"]
  17. }()
  18.  
  19. override func viewDidLoad() {
  20. super.viewDidLoad()
  21. self.title = "UITableView的基本用法"
  22. }
  23. }
  24.  
  25. extension RootViewController:UITableViewDelegate,UITableViewDataSource
  26. {
  27. //区的个数
  28. func numberOfSectionsInTableView(tableView: UITableView) -> Int {
  29. return
  30. }
  31. //在相应区中cell的个数
  32. func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  33. return datas.count
  34. }
  35. // cell的高度
  36. func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
  37. return
  38. }
  39.  
  40. func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
  41. //在重用机制里取出cell
  42. var cell = tableView.dequeueReusableCellWithIdentifier("cell")
  43. //如果cell为空则创建
  44. if cell == nil {
  45. cell = UITableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: "cell")
  46. }
  47. //设置数据
  48. cell?.textLabel?.text = datas[indexPath.row]
  49. return cell!
  50. }
  51.  
  52. }

SWIFT UITableView的基本用法的更多相关文章

  1. Swift - UITableView展开缩放动画

    Swift - UITableView展开缩放动画 效果 源码 https://github.com/YouXianMing/Swift-Animations // // HeaderViewTapA ...

  2. Swift - UITableView状态切换效果

    Swift - UITableView状态切换效果 效果 源码 https://github.com/YouXianMing/Swift-Animations // // TableViewTapAn ...

  3. Swift - UITableView的用法

    因为倾向于纯代码编码,所以不太喜欢可视化编程,不过也略有研究,所以项目里面的所有界面效果,全部都是纯代码编写! 终于到了重中之重的tableview的学习了,自我学习ios编程以来,工作中用得最多的就 ...

  4. IOS SWIFT UITableView 实现简单微博列表

    // // Weibo.swift // UITableViewCellExample // // Created by XUYAN on 15/8/15. // Copyright (c) 2015 ...

  5. Swift枚举的全用法

    鉴于昨天开会部门会议讨论的时候,发现有些朋友对枚举的用法还是存在一些疑问,所以就写下这个文章,介绍下Swift下的枚举的用法. 基本的枚举类型 来,二话不说,我们先贴一个最基本的枚举: enum Mo ...

  6. Swift - UITableView里的cell底部分割线左侧靠边

    override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, ...

  7. IOS第七天(1:UiTableView 的基本用法)

    ***表格控件 #import "HMViewController.h" @interface HMViewController () <UITableViewDataSou ...

  8. 【iOS】swift 排序Sort函数用法(包含NSDictionary排序)

    用了几分钟做的简单翻译 一个例子 直接贴代码,不过多解释 //这是我们的model class imageFile { var fileName = String() var fileID = Int ...

  9. ios初识UITableView及简单用法二(模型数据)

    // // ViewController.m // ZQRTableViewTest // // Created by zzqqrr on 17/8/24. // Copyright (c) 2017 ...

随机推荐

  1. 提取安卓手机的recovery

    一直都是从网上下载的recovery文件安装到手机.至于这个小小的recovery到底是什么全然不知.能不能自己做一个recovery呢?因为功能比较多的clockworkmod(简称cmw)的官网上 ...

  2. vim vi 及其相关插件的使用

    GIMP->linux下16位图查看工具 实用手册:130+ 提高开发效率的 vim 常用命令 http://www.cnblogs.com/lhb25/p/130-essential-vim- ...

  3. mobile cpu上禁用alpha test的相关总结

       因为,每家芯片的特性不同,根据向framebuffer写法的不同,分为tile-based的mobile cpu,如ImgTec PowerVR,ARM Mali,一部分老版本Qualcomm  ...

  4. 20145235 《Java程序设计》第10周学习总结

    教材学习内容总结 网络编程 网络编程对于很多的初学者来说,都是很向往的一种编程技能,但是很多的初学者却因为很长一段时间无法进入网络编程的大门而放弃了对于该部分技术的学习. 程序员所作的事情就是把数据发 ...

  5. Introducing the Accelerated Mobile Pages Project, for a faster, open mobile web

    https://googleblog.blogspot.com/2015/10/introducing-accelerated-mobile-pages.html October 7, 2015 Sm ...

  6. 耦合 Coupling the object-oriented paradigm && data coupling

    Computer Science An Overview _J. Glenn Brookshear _11th Edition 耦 两个人一起耕地 one of the benefits of the ...

  7. Xcode Shortcuts

    Description:⌘: Command     ⌥: Option     ⌃: Control    ←↑↓→: Left, Up, Down, Right                  ...

  8. Excel VBA

    =COUNTIF(Y3:Y212,"=11") =SUMIF(Y3:Y212,"=11",AA3:AA212) =SUMPRODUCT((Y3:Y212=&qu ...

  9. Linux的常用基本命令

    Linux的常用基本命令. 首先启动Linux.启动完毕后需要进行用户的登录,选择登陆的用户不同自然权限也不一样,其中“系统管理员”拥有最高权限. 在启动Linux后屏幕出现如下界面显示: …… Re ...

  10. QDir路径的测试与创建-QT

    #include <QCoreApplication> #include <QDir> #include<QtDebug > #include<QFileIn ...