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) { // } }
一、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") } }
二、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") } }
2、注冊
//zhuce collectionVieww?.register(hometopCell.self, forCellWithReuseIdentifier: "topcell")
3、cellForRow
let cell = collectionVieww?.dequeueReusableCell(withReuseIdentifier: "tuwen", for: indexPath) as! hometuwenCollectionViewCell