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

     

  • 相关阅读:
    odoo14系列笔记-基本进销存(二)
    odoo14系列笔记-基本进销存(一)
    PVE另一种方法使用中科大的镜像服务器 NGINX反向代理
    git 国内加速
    VirtualBox开启套娃模式-打开嵌套 VT-x/AMD-V 功能
    K8S集群安装(基于DEIBAN,proxmox)
    JS语法 ES6、ES7、ES8、ES9、ES10、ES11、ES12新特性
    8个非常实用的Vue自定义指令
    require和import的区别
    js异步加载之defer、async、type=module
  • 原文地址:https://www.cnblogs.com/keqipu/p/6543537.html
Copyright © 2011-2022 走看看