zoukankan      html  css  js  c++  java
  • Swift3.0之UITableViewCell系统样式

    //
    //  ViewController.Swift
    //  Swift demo - UITableViewCell system style
    //
    //  Created by 柯其谱 on 17/3/13.
    //  Copyright © 2017年 柯其谱. All rights reserved.
    //
    
    import UIKit
    
    //MARK: View life cycle
    class ViewController: UIViewController {
    
        override func viewDidLoad() {
            super.viewDidLoad()
            // Do any additional setup after loading the view, typically from a nib.
            self.setupSubviews()
        }
    
        override func didReceiveMemoryWarning() {
            super.didReceiveMemoryWarning()
            // Dispose of any resources that can be recreated.
        }
    
    }
    
    //MARK: Setup
    extension ViewController {
        fileprivate func setupSubviews() -> Void {
            self.setupTableView()
        }
        
        private func setupTableView() -> Void {
            let tableView = UITableView (frame: self.view.frame, style: UITableViewStyle.grouped)
            tableView.delegate = self
            tableView.dataSource = self
            self.view.addSubview(tableView)
        }
    }
    
    //MARK: UITableViewDelegate
    extension ViewController: UITableViewDelegate, UITableViewDataSource {
        func numberOfSections(in tableView: UITableView) -> Int {
            return 4
        }
        
        func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
            return 1
        }
        
        func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
            var cellId: String
            var cell: UITableViewCell? = nil
            var style: UITableViewCellStyle
            let image = UIImage (named: "cellImage")
            var text: String
            let detailText = "detail_text"
            switch indexPath.section {
            case 0:
                cellId = "default"
                style = UITableViewCellStyle.default
                text = "default_text"
            case 1:
                cellId = "subtitle"
                style = UITableViewCellStyle.subtitle
                text = "subtitle_text"
            case 2:
                cellId = "value1"
                style = UITableViewCellStyle.value1
                text = "value1_text"
            default:
                cellId = "value2"
                style = UITableViewCellStyle.value2
                text = "value2_text"
            }
            cell = tableView.dequeueReusableCell(withIdentifier: cellId)
            if cell == nil {
                cell = UITableViewCell (style: style, reuseIdentifier: cellId)
            }
            cell?.imageView?.image = image
            cell?.textLabel?.text = text
            cell?.detailTextLabel?.text = detailText
            cell?.accessoryType = UITableViewCellAccessoryType.disclosureIndicator
            return cell!
        }
    }
    

     

  • 相关阅读:
    shell 指定范围产生随机数
    shell脚本比较两个数大小
    Shell 脚本实现随机抽取班级学生
    linux通过挂载系统光盘搭建本地yum仓库的方法
    kuberenetes 上使用helm部署rancher如何卸载干净
    Windows 下 左Ctrl和Caps交换
    C#笔记 -- 协变、逆变
    Python 读取window下UTF-8-BOM 文件
    生成命令行程序使用脚本
    ffmpeg 命令小记
  • 原文地址:https://www.cnblogs.com/keqipu/p/6543537.html
Copyright © 2011-2022 走看看