swift-UITableView的基本使用
废话不多说了,直接贴我今天写的代码吧:如果新手有什么不懂的,可以发我邮箱。
//
// singleInfo.swift 个人信息
// Housekeeper
//
// Created by 卢洋 on 15/10/27.
// Copyright © 2015年 奈文摩尔. All rights reserved.
//
import Foundation
import UIKit
class singleInfo:UIViewController,UITableViewDataSource,UITableViewDelegate{
var dataTable:UITableView!; //数据表格
var itemString=["昵称","账号","性别","地区","我的爱车"]
//当前屏幕对象
var screenObject=UIScreen.mainScreen().bounds;
//页面初始化
override func viewDidLoad() {
super.viewDidLoad();
initView();
}
/**
UI 初始化
*/
func initView(){
self.title="我的资料";
self.view.backgroundColor=UIColor.linghtGreyBg();
creatTable();
}
/**
我的资料表格初始化
*/
func creatTable(){
let dataTableW:CGFloat=screenObject.width;
let dataTableH:CGFloat=screenObject.height;
let dataTableX:CGFloat=0;
let dataTableY:CGFloat=0;
dataTable=UITableView(frame: CGRectMake(dataTableX, dataTableY, dataTableW, dataTableH),style:UITableViewStyle.Grouped);
dataTable.delegate=self; //实现代理
dataTable.dataSource=self; //实现数据源
//去掉表格分割线
//dataTable.separatorStyle = UITableViewCellSeparatorStyle.None;
self.view.addSubview(dataTable);
}
//1.1默认返回一组
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 2;
}
// 1.2 返回行数
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if(section == 0){
return 1;
}else{
return 5;
}
}
//1.3 返回行高
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat{
if(indexPath.section == 0){
return 80;
}else{
return 55;
}
}
//1.4每组的头部高度
func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return 10;
}
//1.5每组的底部高度
func tableView(tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
return 1;
}
//1.6 返回数据源
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let identifier="identtifier";
var cell=tableView.dequeueReusableCellWithIdentifier(identifier);
if(cell == nil){
cell=UITableViewCell(style: UITableViewCellStyle.Value1, reuseIdentifier: identifier);
}
if(indexPath.section == 0){
cell?.textLabel?.text="头像";
}else{
cell?.textLabel?.text=itemString[indexPath.row];
}
cell?.accessoryType=UITableViewCellAccessoryType.DisclosureIndicator;
return cell!;
}
//1.7 表格点击事件
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
//取消选中的样式
tableView.deselectRowAtIndexPath(indexPath, animated: true);
//获取点击的行索引
if(indexPath.row == 0){
let pushSingleInfo=singleInfo();
pushSingleInfo.hidesBottomBarWhenPushed=true; //隐藏导航栏
self.navigationController?.pushViewController(pushSingleInfo, animated: true);
}
}
//内存警告
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning();
print("个人信息内存警告");
}
}
效果图如下:
swift-UITableView的基本使用的更多相关文章
- Swift - UITableView展开缩放动画
Swift - UITableView展开缩放动画 效果 源码 https://github.com/YouXianMing/Swift-Animations // // HeaderViewTapA ...
- Swift - UITableView状态切换效果
Swift - UITableView状态切换效果 效果 源码 https://github.com/YouXianMing/Swift-Animations // // TableViewTapAn ...
- IOS SWIFT UITableView 实现简单微博列表
// // Weibo.swift // UITableViewCellExample // // Created by XUYAN on 15/8/15. // Copyright (c) 2015 ...
- Swift - UITableView里的cell底部分割线左侧靠边
override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, ...
- SWIFT UITableView的基本用法
import UIKit @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate { var window: ...
- Swift - UITableView的用法
因为倾向于纯代码编码,所以不太喜欢可视化编程,不过也略有研究,所以项目里面的所有界面效果,全部都是纯代码编写! 终于到了重中之重的tableview的学习了,自我学习ios编程以来,工作中用得最多的就 ...
- Swift UITableView嵌套UICollectionView点击事件冲突(点击事件穿透)
不管是啥都响应tableviewcell class JYShopCertificationCell: UITableViewCell { override func hitTest(_ point: ...
- iOS Swift 模块练习/swift基础学习
SWIFT项目练习 SWIFT项目练习2 iOS Swift基础知识代码 推荐:Swift学习使用知识代码软件 0.swift中的宏定义(使用方法代替宏) 一.视图 +控件 1.UIImag ...
- IOS ViewTable
// // ViewController.swift // UITableView // // Created by lanou on 16/11/7. // Copyright (c) 20 ...
- iOS播放器、Flutter高仿书旗小说、卡片动画、二维码扫码、菜单弹窗效果等源码
iOS精选源码 全网最详细购物车强势来袭 一款优雅易用的微型菜单弹窗(类似QQ和微信右上角弹窗) swift, UITableView的动态拖动重排CCPCellDragger 高仿书旗小说 Flut ...
随机推荐
- array_change_key_case()
定义和用法 array_change_key_case() 函数将指定数组的所有的键进行大小写转换. 如果数组的键(索引)为数字则不发生变化.如果未提供第二个参数,则默认转换为小写. 语法 array ...
- CF #329 D
D题,LCA是很明显的.要注意的是,因为是除法,所以最多可以除x>2的有64次,当大于64时可以直接返回0.而且注意到可能会有很多值为1的边,可以使用路径压缩,把边为1的边压缩掉,类似于并查集的 ...
- HDU 4598
这道题其实不需要考虑具体数值,但可以肯定的是,相连边的两端点必定有一正一负,至于谁正谁负,并不重要,这是可以思考的,很明显的一个二分图性质,如果不满足此条件,是不可能满足题目第二个条件的.所以首先对题 ...
- Android 开发 ContentProvider 获取歌曲列表和联系人的样例
ContentProvider(内容提供者)是Android中的四大组件之中的一个. 主要用于对外共享数据.也就是通过ContentProvider把应用中的数据共享给其它应用訪问.其它应用能够通过C ...
- Swoole源代码学习记录(十二)——ReactorThread模块
Swoole版本号:1.7.5-stable Github地址:https://github.com/LinkedDestiny/swoole-src-analysis 这一章将分析Swoole的Re ...
- hive学习路线
hive学习路线图:
- Spring发送邮件_javax.mail.AuthenticationFailedException异常已解决
在Spring项目中须要增加监控功能.监控过程中发现异常时.须要邮件报警.最初选择用javamail发送,代码量比較大(相对于spring发送).终于选择Spring邮件发送~ 以下贴一下实现的代码以 ...
- 实例介绍Cocos2d-x中Box2D物理引擎:碰撞检測
在Box2D中碰撞事件通过实现b2ContactListener类函数实现,b2ContactListener是Box2D提供的抽象类,它的抽象函数:virtual void BeginContact ...
- cocos2d-x 3.1.1 学习笔记[16] Particle 粒子效果
//plist文件中面有粒子效果的各种參数 //textureFileName相应着使用粒子的图片 auto particle = ParticleSystemQuad::create("s ...
- IE6、IE7的兼容问题
通常,网页的兼容问题,就是IE6\IE7的问题.表现为错位.换行,不支持CSS3等. 而其中,错位.换行,原因往往在于没有指明元素的width.height. 一般银瓦不告诉他.