国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

swift-UITableView的基本使用

2019-11-14 18:04:19
字體:
來源:轉載
供稿:網友

廢話不多說了,直接貼我今天寫的代碼吧:如果新手有什么不懂的,可以發我郵箱。

//

//  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;    //實現數據源

        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("個人信息內存警告");

    }

}

效果圖如下:


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 贵州省| 澜沧| 秀山| 南华县| 新余市| 华容县| 永胜县| 和平县| 大石桥市| 江阴市| 凤庆县| 资中县| 舟曲县| 尚志市| 乌鲁木齐市| 会宁县| 姚安县| 黄石市| 东乡县| 萝北县| 米林县| 新邵县| 遵化市| 衡南县| 通许县| 南和县| 锡林郭勒盟| 吕梁市| 曲阜市| 科技| 宁海县| 咸宁市| 康平县| 郸城县| 鸡东县| 德江县| 临猗县| 万源市| 嘉黎县| 谢通门县| 温宿县|