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

//

//  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. 个人常常使用的一些Eclipse技巧

    引言 为了加快开发效率,方便地浏览源代码,重构以及重写一些方法等,Eclipse给我们提供了非常多方便的快捷键以及小技巧.以下是我总结一下经常使用的快捷键和技巧. 快捷键 清理控制台(console) ...

  2. spring+springmvc+hibernate架构、maven分模块开发样例小项目案例

    maven分模块开发样例小项目案例 spring+springmvc+hibernate架构 以用户管理做測试,分dao,sevices,web层,分模块开发測试!因时间关系.仅仅測查询成功.其它的准 ...

  3. Java类集-list

    Collection 子接口: ArrayList是List 接口和Collection接口的一个子类,用于实例化两种接口 package leiji; import java.util.ArrayL ...

  4. setprecision、fixed、showpoint的用法总结(经典!!超经典!!)【转】

    本文转载自:http://blog.csdn.net/u011321546/article/details/9293547 首先要加头文件:iomanip 一:setprecision 作用:控制输出 ...

  5. 批量梯度下降(Batch gradient descent) C++

    At each step the weight vector is moved in the direction of the greatest rate of decrease of the err ...

  6. 78.员工个人信息保镖页面 Extjs 页面

    1 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8" ...

  7. Coursera Algorithms week3 快速排序 练习测验: Nuts and bolts

    题目原文: Nuts and bolts. A disorganized carpenter has a mixed pile of n nuts and n bolts. The goal is t ...

  8. (Go)09.指针赋值修改示例

      答案: 1 package main 2 import ( 3 "fmt" 4 ) 5 6 7 func modify(p *int) { 8 fmt.Println(p) 9 ...

  9. Django day01 web应用程序 , http协议

    一:web应用程序1.什么是web应用程序 是一种可以通过web访问的应用程序,最大的好处就是, 只要有浏览器,用户就能很容易访问到应用程序 2. web应用程序的优缺点 缺点: 应用程序强调了浏览器 ...

  10. WinSocket简单聊天程序客户端

    #pragma comment(lib,"Ws2_32.lib") #include <stdio.h> #include <Winsock2.h> SOC ...