廢話不多說了,直接貼我今天寫的代碼吧:如果新手有什么不懂的,可以發(fā)我郵箱。
//
// singleInfo.swift 個(gè)人信息
// Housekeeper
//
// Created by 盧洋 on 15/10/27.
// Copyright © 2015年 奈文摩爾. All rights reserved.
//
import Foundation
import UIKit
class singleInfo:UIViewController,UITableViewDataSource,UITableViewDelegate{
var dataTable:UITableView!; //數(shù)據(jù)表格
var itemString=["昵稱","賬號(hào)","性別","地區(qū)","我的愛車"]
//當(dāng)前屏幕對(duì)象
var screenObject=UIScreen.mainScreen().bounds;
//頁(yè)面初始化
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; //實(shí)現(xiàn)代理
dataTable.dataSource=self; //實(shí)現(xiàn)數(shù)據(jù)源
self.view.addSubview(dataTable);
}
//1.1默認(rèn)返回一組
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 2;
}
// 1.2 返回行數(shù)
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 返回?cái)?shù)據(jù)源
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 表格點(diǎn)擊事件
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
//取消選中的樣式
tableView.deselectRowAtIndexPath(indexPath, animated: true);
//獲取點(diǎn)擊的行索引
if(indexPath.row == 0){
let pushSingleInfo=singleInfo();
pushSingleInfo.hidesBottomBarWhenPushed=true; //隱藏導(dǎo)航欄
self.navigationController?.pushViewController(pushSingleInfo, animated: true);
}
}
//內(nèi)存警告
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning();
PRint("個(gè)人信息內(nèi)存警告");
}
}
效果圖如下:
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注