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 ...
随机推荐
- Ant Tasks 使用总结
xmlproperty http://ant.apache.org/manual/Tasks/xmlproperty.html Ant的xmlproperty的Task能直接读取一个xml文件以生成相 ...
- mongodb 手动分片的命令汇总
手动分片的操作 自动分片会带来性能的下降. 所以要合理使用手动分片. 并且配合Tag一起使用. # 对于4个shard的程序, 预先处理的指令1. 加入分片服务器sh.addShard( " ...
- Radeon HD 7850 vs Radeon R9 270X
Radeon HD 7850 vs Radeon R9 270X HW compare Intro The Radeon HD 7850 comes with a GPU core speed ...
- Web 在线文件管理器学习笔记与总结(15)剪切文件夹 (16)删除文件夹
(15)剪切文件夹 ① 通过rename($oldname,$newname) 函数实现剪切文件夹的操作 ② 需要检测目标文件夹是否存在,如果存在还要检测目标目录中是否存在同名文件夹,如果不存在则剪切 ...
- Web 在线文件管理器学习笔记与总结(4)查看文件内容
② 查看文件内容 a.通过 file_get_contents($filename) 得到文件内容 b.通过 highlight_string($string) 或者 highlight_file($ ...
- php 文件和表单内容一起上传
<?php $filename = $_POST['filename']; $explain = $_POST['explain']; $upfile = $_FILES['upfile']; ...
- Apache Kafka源码分析 - autoLeaderRebalanceEnable
在broker的配置中,auto.leader.rebalance.enable (false) 那么这个leader是如何进行rebalance的? 首先在controller启动的时候会打开一个s ...
- JAVA Exchanger
//Exchanger工具类的使用案例 //本文给出一个简单的例子,实现两个线程之间交换数据,用Exchanger来做非常简单. import java.util.concurrent.Exchang ...
- SQLServer2008:助您轻松编写T-SQL存储过程(原创)【转】
本文主要介绍 SQLServerExpress2008不用第三方工具调试T-SQL语句,经过本文的介绍,用SQLSERVER2008 Manage studio 编写.调试T-SQL存储过程都将是 ...
- c#循环迭代匿名类链表(可迭代的匿名类)
Main(){ //为什么?object是基类啊!! //报错.不能从List<anonymous>换成List<object>. //var q=(List<objec ...