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

//

//  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. ubuntu设置不睡眠的方法

    Ubuntu系统不睡眠设置方法:要完成这个设置Ubuntu有两种方法:第一种是打开 System Settings –> Power,中文版是打开系统设置 -> 电源),然后进行设置.但不 ...

  2. 学习C#和SQL的书籍

    1. <21天学通C#> 周红安等编著  电子工业出版社 2.  http://blog.csdn.net/21aspnet/article/details/1682200 3. < ...

  3. linux 获取经过N层Nginx转发的访问来源真实IP

    linux 获取经过N层Nginx转发的访问来源真实IP 学习:http://blog.csdn.net/zhenzhendeblog/article/details/49702575 学习:http ...

  4. Hadoop - YARN 启动流程

       一  YARN的启动流程                                                                 watermark/2/text/aHR ...

  5. 运用smali自己主动注入技术分析android应用程序行为

    如今android开发人员社区里,除了app开发外,还有非常多周边的工具类产品,比方安全.性能等,app产品 已经出现了巨无霸,可是工具类的产品.眼下还没有出现规模比較大的公司,大部分还处于创业阶段, ...

  6. JQuery实现复制到剪贴板功能

    在网页中实现复制到剪贴板功能,有两种方法, 第1种方法:使用JavaScript自带的方法,但是这种方法只能在IE下使用. document.execCommand("Copy") ...

  7. How to do IF NOT EXISTS in SQLite

    http://stackoverflow.com/questions/531035/how-to-do-if-not-exists-in-sqlite How about this? INSERT O ...

  8. mongodb 3.2配置内存缓存大小为MB/MongoDB 3.x内存限制配置

    mongodb 3.2配置内存缓存大小为MB/MongoDB 3.x内存限制配置 转载自勤奋的小青蛙 mongodb占用内存非常高,这是因为官方为了提升存储的效率,设计就这么设计的. 但是大部分的个人 ...

  9. 99.ext afteredit事件详解

    转自:http://www.jcodecraeer.com/a/jquery_js_ajaxjishu/2012/0524/203.html 1 摘要 grid.on(afteredit,afterE ...

  10. autofac的小知识点

    autofac 注入中i遇到的泛型传参问题 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 ...