• 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!
        }
    }
    

     

  • 相关阅读:
    Grunt构建工具插件篇——之less工具
    Grunt构建工具能做哪些事?
    Grunt-几个常用的任务配置,加载,执行的写法
    单元测试任务包括哪些?
    单元测试的概念
    分享Grunt.js配置: watch + liveReload 实时监测文件变化自动刷新浏览器
    如何使用Grunt(好文)
    grunt安装详解及失败处理
    利用 Grunt (几乎)无痛地做前端开发 (一)之单元测试
    Grunt实现自动化单元测试
  • 原文地址:https://www.cnblogs.com/keqipu/p/6543537.html
Copyright © 2020-2023  润新知