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

//

//  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. 【Linux】Ubuntu 开机默认亮度改动方法

    换了ubuntu 之后.发现开机屏幕都是"最大亮度",每次都要到设置中手动调节,非常麻烦.于是想到去改动这个设置.Google一通,别人可行的办法到我这就没用了.郁闷.最后是在st ...

  2. redis client 2.0.0 pipeline 的list的rpop bug

    描写叙述: redis client 2.0.0 pipeline 的list的rpop 存在严重bug,rpop list的时候,假设list已经为空的时候,rpop出来的Response依旧不为n ...

  3. luogu3084 Photo 单调队列优化DP

    题目大意 农夫约翰决定给站在一条线上的N(1 <= N <= 200,000)头奶牛制作一张全家福照片,N头奶牛编号1到N.于是约翰拍摄了M(1 <= M <= 100,000 ...

  4. 窗口函数 SELECT - OVER Clause (Transact-SQL)

    https://docs.microsoft.com/en-us/sql/t-sql/queries/select-over-clause-transact-sql Determines the pa ...

  5. golang文件读写三种方式——bufio,ioutil和os.create

    package main import ( "bufio" "fmt" "io/ioutil" "os" ) func ...

  6. hihocoder 1680 hiho字符串2 dp求方案数+递归

    我们定义第一代hiho字符串是"hiho". 第N代hiho字符串是由第N-1代hiho字符串变化得到,规则是: h -> hio i -> hi o -> ho ...

  7. warning: here-document at line 7 delimited by end-of-file (wanted `rui')

  8. 利用html sessionStorge 来保存局部页面在刷新后回显,保留

    转自:https://blog.csdn.net/u011085172/article/details/77320562 在一个页面里面,有个局部页面记录这当前session的任务记录,之前用的coo ...

  9. JPA新增entity时自动填充时间,例创建时间,修改时间

    背景:springboot项目,集成JPA,与数据库交互的entity,与用户交互的DTO 问题:添加酒店时,两个字段create_time,update_time,前端不传数据,如果赋值 解决: 1 ...

  10. HBase编程 API入门系列之get(客户端而言)(2)

    心得,写在前面的话,也许,中间会要多次执行,连接超时,多试试就好了. 前面是基础,如下 HBase编程 API入门系列之put(客户端而言)(1) package zhouls.bigdata.Hba ...