Netease-Music-Demo/wyy/SideBar/SideBarView.swift

72 lines
2.1 KiB
Swift
Raw Normal View History

2021-03-06 18:45:01 +08:00
//
// SideBarView.swift
// wyy
//
// Created by on 2021/3/6.
//
import UIKit
import SnapKit
class SideBarView: UIView, UITableViewDataSource, UITableViewDelegate {
struct SideBarCellData {
var imageName: String
var title: String
}
let centerTableView = UITableView()
var centerTableData = [SideBarCellData(imageName: "discover", title: "消息中心"),
SideBarCellData(imageName: "discover", title: "消息中心"),
SideBarCellData(imageName: "discover", title: "消息中心")]
init(){
super.init(frame: CGRect(x: 0, y: 0, width: 300, height: 1000))
addSubview(centerTableView)
centerTableView.dataSource = self
centerTableView.delegate = self
centerTableView.snp.makeConstraints { make in
make.top.equalTo(20)
make.centerX.equalToSuperview()
make.width.equalTo(300)
make.height.equalTo(800)
}
centerTableView.reloadData()
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
switch tableView {
case centerTableView:
return centerTableData.count
default:
return 0
}
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cellID = "sideBarCell"
var cell: SideBarCell? = tableView.dequeueReusableCell(withIdentifier: cellID) as? SideBarCell
if cell == nil {
cell = SideBarCell(style: .subtitle, reuseIdentifier: cellID)
}
var data: SideBarCellData
switch tableView {
case centerTableView:
data = centerTableData[indexPath.row]
default:
data = centerTableData[indexPath.row]
}
cell?.iconImageView.image = UIImage(named: data.imageName)
cell?.titleLabel.text = data.title
print(111)
return cell!
}
}