swift-UITableView的基本使用
废话不多说了,直接贴我今天写的代码吧:如果新手有什么不懂的,可以发我邮箱。
//
// 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的基本使用的更多相关文章
- Swift - UITableView展开缩放动画
Swift - UITableView展开缩放动画 效果 源码 https://github.com/YouXianMing/Swift-Animations // // HeaderViewTapA ...
- Swift - UITableView状态切换效果
Swift - UITableView状态切换效果 效果 源码 https://github.com/YouXianMing/Swift-Animations // // TableViewTapAn ...
- IOS SWIFT UITableView 实现简单微博列表
// // Weibo.swift // UITableViewCellExample // // Created by XUYAN on 15/8/15. // Copyright (c) 2015 ...
- Swift - UITableView里的cell底部分割线左侧靠边
override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, ...
- SWIFT UITableView的基本用法
import UIKit @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate { var window: ...
- Swift - UITableView的用法
因为倾向于纯代码编码,所以不太喜欢可视化编程,不过也略有研究,所以项目里面的所有界面效果,全部都是纯代码编写! 终于到了重中之重的tableview的学习了,自我学习ios编程以来,工作中用得最多的就 ...
- Swift UITableView嵌套UICollectionView点击事件冲突(点击事件穿透)
不管是啥都响应tableviewcell class JYShopCertificationCell: UITableViewCell { override func hitTest(_ point: ...
- iOS Swift 模块练习/swift基础学习
SWIFT项目练习 SWIFT项目练习2 iOS Swift基础知识代码 推荐:Swift学习使用知识代码软件 0.swift中的宏定义(使用方法代替宏) 一.视图 +控件 1.UIImag ...
- IOS ViewTable
// // ViewController.swift // UITableView // // Created by lanou on 16/11/7. // Copyright (c) 20 ...
- iOS播放器、Flutter高仿书旗小说、卡片动画、二维码扫码、菜单弹窗效果等源码
iOS精选源码 全网最详细购物车强势来袭 一款优雅易用的微型菜单弹窗(类似QQ和微信右上角弹窗) swift, UITableView的动态拖动重排CCPCellDragger 高仿书旗小说 Flut ...
随机推荐
- 编程之美初赛第二场AB
题目1 : 扑克牌 时间限制:2000ms 单点时限:1000ms 内存限制:256MB 描述 一副不含王的扑克牌由52张牌组成,由红桃.黑桃.梅花.方块4组牌组成,每组13张不同的面值.现在给定52 ...
- Application Framework层介绍
http://write.blog.csdn.net/postedithttp://write.blog.csdn.net/postedithttp://write.blog.csdn.net/pos ...
- RPC通信功能实现
Table of Contents RPC通信功能实现 配置參数 调用方法 RPC通信功能实现 HBase的RPC通信功能主要基于Protobuf和NIO这两个组件来实现.在通信管道上选择的是prot ...
- Zoj 3535 Gao the String II (AC自己主动机+dp)
题目大意: 用集合A中的串构造出一个串,使之让很多其它的setB中的串成为他的子串. 思路分析: 和 Codeforces 86C 几乎相同. 只是这里是要用A中的构造. 先用A 和 B的串构造一个自 ...
- .m文件导入C++头文件带来的错误
这几天的工作挖了不少的坑.遇到了各种千奇百怪的错误,如今好好总结一下. 新建一个project,然后新建HelloCPP.h,HelloCPP.cpp文件.HelloCPP.h文件内容例如以下: #i ...
- Ambarella SDK build 步骤解析
Make Target Options make命令如下: make <Tab> <Tab> /*列出所有支持的目标(命令行输入make, 再按两下Tab键)*/ make & ...
- Git 少用 Pull 多用 Fetch 和 Merge 【已翻译100%】【转】
本文转载自:https://www.oschina.net/translate/git-fetch-and-merge?lang=chs&page=1# 本文有点长而且有点乱,但就像Mark ...
- Android入门之文件系统操作(二)文件操作相关指令
(一)获取总根 File[] fileList=File.listRoots(); //返回fileList.length为1 //fileList.getAbsolutePath()为"/ ...
- ssdb底层实现——ssdb底层是leveldb,leveldb根本上是skiplist(例如为存储多个list items,必然有多个item key,而非暴力string cat),用它来做redis的list和set等,势必在数据结构和算法层面上有诸多不适
我已经在用ssdb的hash结构,存储了很多数据了,但是我现在的用法正确吗? 我使用hash结构合理吗? 1. ssdb数据库说是类似redis,而且他们都有hash结构,但是他们的命名有点不同,ss ...
- linux 编译安装TRMPdump(libRTMP)
需要编译libRTMP,首先需要安装配置编译环境.网上能够找到的资料多是在Windows环境编译.这里介绍一下在Linux系统中编译安装libRTMP,一来给后来者一个参考,二来也给自己做一个备忘录. ...