zoukankan      html  css  js  c++  java
  • Swift3.0 自定义tableView复用cell 的写法,与CollectionViewCell的不同,数据model

     Model数据

    class HospitalModel: NSObject {
        //后边不赋值 会报错
        var imgurl :String = ""
        var introduction : String = ""
        var kind :String = ""
        var lat: Float = 0
        var lng : Float = 0
        var medinsurance : Int = 0
        var name : String = ""
        var org_code : String = ""
        var recommend : Int = 0
        var regaddr : String = ""
        var regregion : Int = 0
        var linked : Int  = 0//连接状态 0
        
        //当模型数据 少于网络的时候
    //    override func setValue(value:AnyObject?, forUndefinedKey key:String) {
    //    }
    }
    Model

    一、tableViewCell

    1.声明注册 cell, 选择要注册的是class还是nib

    **********快捷键:      Command+Shift+4      截取屏并自动保存在桌面***********

    cell的写法是 Cell名称.self

     tableview.register(homecellTable.self, forCellReuseIdentifier: "cell")

    2、在cellForRow中      判断cell是否为空的方法 这个可行,有其他的欢迎留言

      var cell : homecellTable = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! homecellTable
            
            if cell.isEqual(nil) {
                
                cell = homecellTable(style: .default, reuseIdentifier: "cell")
                
            }

    3、自定义cell布局

    class homeYiyuancellTable: UITableViewCell {
        
        var imageyiyuan = UIImageView()
        var labelyiyuan = UILabel()
       
        
        override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
            
            super.init(style: style, reuseIdentifier: reuseIdentifier)
            
            self.backgroundColor = UIColor.white
     
            //此处开始布局
            
        }
        
        required init?(coder aDecoder: NSCoder) {
            fatalError("init(coder:) has not been implemented")
        }
        
        
    }
    cell写法

    二、CollectionViewCell 的写法

    1、首先 cell的自定义上的不同

    class homeYiyuancell: UICollectionViewCell {
        
        var imageyiyuan = UIImageView()
        var labelyiyuan = UILabel()
      
        
        override init(frame: CGRect) {
            super.init(frame: frame)
            
            self.backgroundColor = UIColor.white
           //开始布局
            
        }
        
        required init?(coder aDecoder: NSCoder) {
            fatalError("init(coder:) has not been implemented")
        }
       
        
    }
    cell 写法

    2、注册

    //zhuce
            collectionVieww?.register(hometopCell.self, forCellWithReuseIdentifier: "topcell")

    3、cellForRow

     let cell = collectionVieww?.dequeueReusableCell(withReuseIdentifier: "tuwen", for: indexPath) as! hometuwenCollectionViewCell
  • 相关阅读:
    015.Delphi插件之QPlugins,FMX插件窗口
    014.Delphi插件之QPlugins,MDI窗口
    013.Delphi插件之QPlugins,模块化代码示例
    012.Delphi插件之QPlugins,多实例内嵌窗口服务
    011.Delphi插件之QPlugins,延时加载服务
    010.Delphi插件之QPlugins,遍历服务接口
    009.Delphi插件之QPlugins,服务的热插拔
    008.Delphi插件之QPlugins,服务的两种调用方法
    007.Delphi插件之QPlugins,插件的卸载和重新加载
    006.Delphi插件之QPlugins,多服务演示
  • 原文地址:https://www.cnblogs.com/xujiahui/p/7266848.html
Copyright © 2011-2022 走看看