swift-UITableView的根本使用

swift-UITableView的根本使用,第1张

概述swift-UITableView的基本使用 废话不多说了,直接贴我今天写的代码吧:如果新手有什么不懂的,可以发我邮箱。 // //  singleInfo.swift            个人信息 //  Housekeeper // //  Created by 卢洋 on 15/10/27. //  Copyright © 2015年 奈文摩尔. All rights reserved. swift-UItableVIEw的基本使用

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

//

// singleInfo.swift 个人信息

// Housekeeper

//

// Created by卢洋on 15/10/27.

// copyright © 2015奈文摩尔. All rights reserved.

//

importFoundation

importUIKit

classsingleInfo:UIVIEwController,UItableVIEwDataSource,UItableVIEwDelegate{

vardatatable:UItableVIEw!; //数据表格

varitemString=["昵称","账号","性别","地区","我的爱车"]

 //当前屏幕对象

  varscreenObject=UIScreen.mainScreen().bounds;

//页面初始化

overrIDefuncvIEwDIDLoad() {

super.vIEwDIDLoad();

initVIEw();

}

/**

UI初始化

*/

funcinitVIEw(){

self.Title="我的资料";

self.vIEw.backgroundcolor=UIcolor.linghtGreyBg();

creattable();

}

/**

我的资料表格初始化

*/

funccreattable(){

letdatatableW:CGfloat=screenObject.wIDth;

letdatatableH:CGfloat=screenObject.height;

letdatatableX:CGfloat=0;

letdatatableY:CGfloat=0;

datatable=UItableVIEw(frame:CGRectMake(datatableX,datatableY,datatableW,datatableH),style:UItableVIEwStyle.Grouped);

datatable.delegate=self;      //实现代理

datatable.dataSource=self;    //实现数据源

self.vIEw.addSubvIEw(datatable);

}

//1.1默认返回一组

funcnumberOfSectionsIntableVIEw(tableVIEw:UItableVIEw) ->Int{

return2;

}

// 1.2返回行数

functableVIEw(tableVIEw:UItableVIEw,numberOfRowsInSection section:Int) ->Int{

if(section ==0){

return1;

}else{

return5;

}

}

//1.3返回行高

functableVIEw(tableVIEw:UItableVIEw,heightForRowAtIndexPath indexPath:NSIndexPath) ->CGfloat{

if(indexPath.section==0){

return80;

}else{

return55;

}

}

//1.4每组的头部高度

functableVIEw(tableVIEw:UItableVIEw,heightForheaderInSection section:Int) ->CGfloat{

return10;

}

//1.5每组的底部高度

functableVIEw(tableVIEw:UItableVIEw,heightForFooterInSection section:Int) ->CGfloat{

return1;

}

//1.6返回数据源

functableVIEw(tableVIEw:UItableVIEw,cellForRowAtIndexPath indexPath:NSIndexPath) ->UItableVIEwCell{

letIDentifIEr="IDenttifIEr";

varcell=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;

returncell!;

}

//1.7表格点击事件

functableVIEw(tableVIEw:UItableVIEw,dIDSelectRowAtIndexPath indexPath:NSIndexPath) {

//取消选中的样式

tableVIEw.deselectRowAtIndexPath(indexPath,animated:true);

   //获取点击的行索引

if(indexPath.row==0){

letpushSingleInfo=singleInfo();

pushSingleInfo.hIDesBottombarWhenPushed=true;    //隐藏导航栏

self.navigationController?.pushVIEwController(pushSingleInfo,animated:true);

}

}

//内存警告

overrIDefuncdIDReceiveMemoryWarning() {

super.dIDReceiveMemoryWarning();

print("个人信息内存警告");

}

}

效果图如下:

总结

以上是内存溢出为你收集整理的swift-UITableView的根本使用全部内容,希望文章能够帮你解决swift-UITableView的根本使用所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://www.outofmemory.cn/web/1074830.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-26
下一篇 2022-05-26

发表评论

登录后才能评论

评论列表(0条)

保存