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

     

  • 相关阅读:
    Maven工程运行环境修改
    Maven中出现org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException错误
    IDEA创建maven_web工程后,右键包没有Servlet、Filter、Listener选项
    Spring中的依赖注入
    什么是JavaBean
    mybatis配置SqlMapConfig.xm时没有提示
    JDK1.8之后匿名内部类访问方法中的局部变量不用加final修饰
    架构、框架和设计模式
    CitrixSQL Server 2016高可用之SQL镜像 SQL Server mirror 带见证服务器
    CitrixPVS BDM启动模式创建虚机 BDM模式部署桌面(精华)
  • 原文地址:https://www.cnblogs.com/keqipu/p/6543537.html
Copyright © 2011-2022 走看看