SWIFT UITableView的基本用法
- import UIKit
- @UIApplicationMain
- class AppDelegate: UIResponder, UIApplicationDelegate {
- var window: UIWindow?
- func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
- self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
- // Override point for customization after application launch.
- self.window!.backgroundColor = UIColor.whiteColor()
- let navigation = UINavigationController(rootViewController: RootViewController())
- self.window?.rootViewController = navigation
- self.window!.makeKeyAndVisible()
- return true
- }
- }
- import UIKit
- class RootViewController: UIViewController {
- override func loadView() {
- super.loadView()
- //初始化UITableView
- let tableView = UITableView()
- tableView.frame = UIScreen.mainScreen().bounds
- tableView.dataSource = self
- tableView.delegate = self
- self.view.addSubview(tableView)
- }
- //懒加载数据
- lazy var datas:[String] = {
- return ["是雨是泪","分分钟需要你","伤心太平洋","曾经最痛","飘雪"]
- }()
- override func viewDidLoad() {
- super.viewDidLoad()
- self.title = "UITableView的基本用法"
- }
- }
- extension RootViewController:UITableViewDelegate,UITableViewDataSource
- {
- //区的个数
- func numberOfSectionsInTableView(tableView: UITableView) -> Int {
- return
- }
- //在相应区中cell的个数
- func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
- return datas.count
- }
- // cell的高度
- func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
- return
- }
- func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
- //在重用机制里取出cell
- var cell = tableView.dequeueReusableCellWithIdentifier("cell")
- //如果cell为空则创建
- if cell == nil {
- cell = UITableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: "cell")
- }
- //设置数据
- cell?.textLabel?.text = datas[indexPath.row]
- return cell!
- }
- }
SWIFT UITableView的基本用法的更多相关文章
- Swift - UITableView展开缩放动画
Swift - UITableView展开缩放动画 效果 源码 https://github.com/YouXianMing/Swift-Animations // // HeaderViewTapA ...
- Swift - UITableView状态切换效果
Swift - UITableView状态切换效果 效果 源码 https://github.com/YouXianMing/Swift-Animations // // TableViewTapAn ...
- Swift - UITableView的用法
因为倾向于纯代码编码,所以不太喜欢可视化编程,不过也略有研究,所以项目里面的所有界面效果,全部都是纯代码编写! 终于到了重中之重的tableview的学习了,自我学习ios编程以来,工作中用得最多的就 ...
- IOS SWIFT UITableView 实现简单微博列表
// // Weibo.swift // UITableViewCellExample // // Created by XUYAN on 15/8/15. // Copyright (c) 2015 ...
- Swift枚举的全用法
鉴于昨天开会部门会议讨论的时候,发现有些朋友对枚举的用法还是存在一些疑问,所以就写下这个文章,介绍下Swift下的枚举的用法. 基本的枚举类型 来,二话不说,我们先贴一个最基本的枚举: enum Mo ...
- Swift - UITableView里的cell底部分割线左侧靠边
override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, ...
- IOS第七天(1:UiTableView 的基本用法)
***表格控件 #import "HMViewController.h" @interface HMViewController () <UITableViewDataSou ...
- 【iOS】swift 排序Sort函数用法(包含NSDictionary排序)
用了几分钟做的简单翻译 一个例子 直接贴代码,不过多解释 //这是我们的model class imageFile { var fileName = String() var fileID = Int ...
- ios初识UITableView及简单用法二(模型数据)
// // ViewController.m // ZQRTableViewTest // // Created by zzqqrr on 17/8/24. // Copyright (c) 2017 ...
随机推荐
- 提取安卓手机的recovery
一直都是从网上下载的recovery文件安装到手机.至于这个小小的recovery到底是什么全然不知.能不能自己做一个recovery呢?因为功能比较多的clockworkmod(简称cmw)的官网上 ...
- vim vi 及其相关插件的使用
GIMP->linux下16位图查看工具 实用手册:130+ 提高开发效率的 vim 常用命令 http://www.cnblogs.com/lhb25/p/130-essential-vim- ...
- mobile cpu上禁用alpha test的相关总结
因为,每家芯片的特性不同,根据向framebuffer写法的不同,分为tile-based的mobile cpu,如ImgTec PowerVR,ARM Mali,一部分老版本Qualcomm ...
- 20145235 《Java程序设计》第10周学习总结
教材学习内容总结 网络编程 网络编程对于很多的初学者来说,都是很向往的一种编程技能,但是很多的初学者却因为很长一段时间无法进入网络编程的大门而放弃了对于该部分技术的学习. 程序员所作的事情就是把数据发 ...
- 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 ...
- 耦合 Coupling the object-oriented paradigm && data coupling
Computer Science An Overview _J. Glenn Brookshear _11th Edition 耦 两个人一起耕地 one of the benefits of the ...
- Xcode Shortcuts
Description:⌘: Command ⌥: Option ⌃: Control ←↑↓→: Left, Up, Down, Right ...
- Excel VBA
=COUNTIF(Y3:Y212,"=11") =SUMIF(Y3:Y212,"=11",AA3:AA212) =SUMPRODUCT((Y3:Y212=&qu ...
- Linux的常用基本命令
Linux的常用基本命令. 首先启动Linux.启动完毕后需要进行用户的登录,选择登陆的用户不同自然权限也不一样,其中“系统管理员”拥有最高权限. 在启动Linux后屏幕出现如下界面显示: …… Re ...
- QDir路径的测试与创建-QT
#include <QCoreApplication> #include <QDir> #include<QtDebug > #include<QFileIn ...