废话不多说了,直接贴我今天写的代码吧:如果新手有什么不懂的,可以发我邮箱。

//

//  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的基本使用的更多相关文章

  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. IOS SWIFT UITableView 实现简单微博列表

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

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

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

  5. SWIFT UITableView的基本用法

    import UIKit @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate { var window: ...

  6. Swift - UITableView的用法

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

  7. Swift UITableView嵌套UICollectionView点击事件冲突(点击事件穿透)

    不管是啥都响应tableviewcell class JYShopCertificationCell: UITableViewCell { override func hitTest(_ point: ...

  8. iOS Swift 模块练习/swift基础学习

    SWIFT项目练习     SWIFT项目练习2 iOS Swift基础知识代码 推荐:Swift学习使用知识代码软件 0.swift中的宏定义(使用方法代替宏) 一.视图  +控件 1.UIImag ...

  9. IOS ViewTable

    // //  ViewController.swift //  UITableView // //  Created by lanou on 16/11/7. //  Copyright (c) 20 ...

  10. iOS播放器、Flutter高仿书旗小说、卡片动画、二维码扫码、菜单弹窗效果等源码

    iOS精选源码 全网最详细购物车强势来袭 一款优雅易用的微型菜单弹窗(类似QQ和微信右上角弹窗) swift, UITableView的动态拖动重排CCPCellDragger 高仿书旗小说 Flut ...

随机推荐

  1. Clojure:解决selmer模板不刷新的问题

    当在REPL环境中尝试调试template的时候,会发现每次都需要重启REPL才能看到最新的变化.调查后发现,原来是每次启动REPL的时候,原来的template文件都被放到了target目录中,这样 ...

  2. CF #319 div 2 D

    这道题算不算脑洞题.. 可以发现,当一个排列中有循环节时长度为1或2时可能有解.当为1时,只需把全部点都连到这个题即可,当为2时,就要求所有循环节长度均为偶数,这很容易理解,因为如果存在为奇数,它们之 ...

  3. Graphics简单汇总

    1.主页面布局文件 activity_main.xml(仅仅有2个button按钮) <?xml version="1.0" encoding="utf-8&quo ...

  4. android 音乐播放器总结

    学习从模仿開始 一个星期完毕的音乐播放器基本功能,具有下一首,上一首,暂停和随机.顺序和单曲等播放.以及保存上一次播放的状态,缺少了歌词显示功能.使用了andbase框架的欢迎动画和界面title. ...

  5. codeforces Looksery Cup 2015 D. Haar Features

    The first algorithm for detecting a face on the image working in realtime was developed by Paul Viol ...

  6. 【概念的辨异】—— ISO C 与 POSIX C(C standard library 与 C POSIX library)

    ISO C 表示 C Standard Library,也就是 C 标准库. 二者的主要区别在于: POSIX 是 C 标准库的超集(也即是从内容上,C 标准库是 POSIX 库的一部分,POSIX ...

  7. bzoj 2005 & 洛谷 P1447 [ Noi 2010 ] 能量采集 —— 容斥 / 莫比乌斯反演

    题目:bzoj 2005 https://www.lydsy.com/JudgeOnline/problem.php?id=2005   洛谷 P1447 https://www.luogu.org/ ...

  8. nodejs windows环境安装

    相信对于很多关注javascript发展的同学来说,nodejs已经不是一个陌生的词眼.有关nodejs的相关资料网上已经铺天盖地.由于它的高并发特性,造就了其特殊的应用地位. 国内目前关注最高,维护 ...

  9. MyEclipse配置https

    1.参照CAS配置(1)SSL证书配置文章配置证书. 2.打开myeclipse的Workspace下的.metadata/.me_tcat7/conf/server.xml 打开文件,添加如下代码 ...

  10. 工具分享3:VMware 10虚拟机、MS-DOS 7.1、安装教程(MS-DOS环境安装)

    VMware 10工具下载地址: 网页下载链接:http://www.xp510.com/xiazai/ossoft/desktools/22610.html MS-DOS .10镜像下载地址: 网页 ...