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

//

//  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. c++ 基于Policy 的 模板编程

    在没真正接触c++  模板编程之前.真的没有想到c++ 还能够这么用.最大的感触是:太灵活了,太强大了. 最初接触模板威力还是在Delta3d中,感觉里面的模板使用实在是灵活与方便,特别是dtAI中使 ...

  2. oc53--autorelease注意事项

    // // main.m // autorelease注意事项 #import <Foundation/Foundation.h> #import "Person.h" ...

  3. Recovery 中的UI知识积累【转】

    本文转载自:http://blog.csdn.net/wed110/article/details/26554197 int gr_init(void);             /* 初始化图形显示 ...

  4. C# 数据库备份与还原 小妹做了一个winform系统,需要对sql2000数据库备份和还原(小妹妹你太狠了)

      成功了,把代码帖出来给大家看看,跟我刚开始帖出来的差不多,是需要杀掉进程的,我之前调用的存储过程,可能有点问题,现在改成sql了/// <summary>        /// 数据库 ...

  5. Java8新特性之Optional

    空指针异常一直是困扰Java程序员的问题,也是我们必须要考虑的.当业务代码中充满了if else判断null 的时候程序变得不再优雅,在Java8中提供了Optional类为我们解决NullPoint ...

  6. iOS获取相册/相机图片-------自定义获取图片小控件

    一.功能简介 1.封装了一个按钮,点击按钮,会提示从何处获取图片:如果设备支持相机,可以从相机获取,同时还可以从手机相册获取图片. 2.选择图片后,有一个block回调,根据需求,将获得的图片拿来使用 ...

  7. clone的rails目录下命令无效问题

    异常坑爹,在公司克隆自己的项目.然后在项目目录下rails s还有一大堆命令无效,提示 Usage: rails new APP_PATH [options]   找了半天总算找到解决办法了,在项目目 ...

  8. E20170813-ts

    explicitly  adv. 明白地,明确地;

  9. CMS内容管理系统 -- WorkSpace

  10. php导出mysql源码

    件名:db_backup.php 源代码如下: 复制代码 代码如下: <?php ini_set("max_execution_time", "180") ...