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 ...
随机推荐
- 一起talk C栗子吧(第七十七回:C语言实例--DIY ls命令续)
各位看官们,大家好.上一回中咱们说的是DIY cat命令的样例.这一回咱们说的样例是:DIY ls命令续. 闲话休提,言归正转.让我们一起talk C栗子吧! 我们在前面的章回中DIY过ls命令.时间 ...
- codeforces 437D The Child and Zoo
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...
- unity中 拖拽随意的对象
孙广东 2015.8.16 目的 : 我们能简单的通过 鼠标位置 得到目标对象 假设没有使用刚体组件 Step - 1: 在3D项目中设置场景. 一个空对象命名为: DragAndDrop ...
- jQuery总结02
1 如何搭建一个 jQuery 环境? 2 jQuery 对象与 DOM 对象一样吗?区别是什么? 3 jQuery选择器类型有哪些?
- Windows热键注册的底层原理
要像系统注册一个全局热键,需要用到RegisterHotKey,函数用法如下(MSDN):BOOL RegisterHotKey( ...
- sharepoint类型转换
sharepoint学习汇总 http://blog.csdn.net/qq873113580/article/details/20390149 r[col.ColumnName] = GetType ...
- 新建项目git clone
- c++之——————各种变量
对我们程序员来讲,“变量”和“对象”是可以相互互换使用的.-------------开篇之词. 变量:提供一个具有名字的可供程序操作的存储空间.由类型说明符和其后紧跟的数个列表组成,其中变量名之间使用 ...
- centos7用rpm安装mysql5.7【初始用yum安装发现下载非常慢,就考虑本地用迅雷下载rpm方式安装】
1.下载 4个rpm包 mysql-community-client-5.7.26-1.el7.x86_64.rpmmysql-community-common-5.7.26-1.el7.x86_64 ...
- net .异步委托知识
以前在编程中,异步用的比较少,导致C# 一些基础的 东西用法都不怎么熟悉,经常要用的时候在去查找资料比较被动,而已没真正里面理解起来,始终感觉不是自己的知识 (题外话) 首先委托关键字 Delega ...