加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Swift UITableView 学习

发布时间:2020-12-14 07:00:53 所属栏目:百科 来源:网络整理
导读:源码如下: import UIKitclass TFNetImageViewController: TFBaseViewController,UITableViewDataSource,UITableViewDelegate{ var TFTableView:UITableView! var itemString = ["姓名","账号","爱好","职业","年薪"] override func viewDidLoad() { super.v

源码如下:

import UIKit

class TFNetImageViewController: TFBaseViewController,UITableViewDataSource,UITableViewDelegate{

    var TFTableView:UITableView!
    var itemString = ["姓名","账号","爱好","职业","年薪"]
    override func viewDidLoad() {
        super.viewDidLoad()

        self.setTopNavBarTitle("个人信息")
        self.setTopNavBackButton()
        self.view.backgroundColor = UIColor.lightGrayColor()
        self.creatTable()
    }
    
    
    func creatTable(){

        TFTableView = UITableView(frame: CGRectMake(0,64,AppWidth,AppHeight - 64),style:UITableViewStyle.Grouped);
        TFTableView.delegate = self;
        TFTableView.dataSource = self;
        self.view.addSubview(TFTableView);
    }
    
    //MARK: UITableViewDataSource
    func numberOfSectionsInTableView(tableView: UITableView) -> Int {
        return 2;
    }
    
    func tableView(tableView: UITableView,numberOfRowsInSection section: Int) -> Int {
        if(section == 0){
            return 1;
        }else{
            return 5;
        }
    }
    
    func tableView(tableView: UITableView,heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat{
        
        if(indexPath.section == 0){
            return 80;
        }else{
            return 55;
            
        }
    }
    
    func tableView(tableView: UITableView,heightForHeaderInSection section: Int) -> CGFloat {
        return 10;
    }
    

    func tableView(tableView: UITableView,heightForFooterInSection section: Int) -> CGFloat {
        return 1;
    }

    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!;
    }
    
    
    //MARK: UITableViewDelegate
    func tableView(tableView: UITableView,didSelectRowAtIndexPath indexPath: NSIndexPath) {
        
        tableView.deselectRowAtIndexPath(indexPath,animated: true);
    }

 }


效果图如下:

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读