func setCellWithData(model:musicModel) -> Void {
self.title.text = model.title
self.pic.text = model.pic
self.time.text = model.time
self.imgV.image = UIImage(named: model.number)
class musicModel: NSObject {
var title:String
var pic:String
var number:String
var time:String
init(title:String,pic:String,number:String,time:String) {
self.title = title
self.pic = pic
self.number = number
self.time = time
}
}
class celldata: NSObject {
static func setcelldata() -> [mymodel] {
let arr = [“男式衬衫”,“男式衬衫”,“男式衬衫”,“男式衬衫”,“男式衬衫”,“男式衬衫”,“男式衬衫”,“男式衬衫”]
let arr2 = [“33:55:22”,“33:55:22”,“33:55:22”,“33:55:22”,“33:55:22”,“33:55:22”,“33:55:22”,“33:55:22”]
let arr3 = [“96件”,“96件”,“96件”,“96件”,“96件”,“96件”,“96件”,“96件”]
let arr4 = [“5”,“5”,“5”,“5”,“5”,“5”,“5”,“5”]
var marr : [mymodel]=[]
for i in 0…<arr.count {
let md = mymodel(title: arr[i], pic: arr4[i], number: arr3[i], time: arr2[i])
marr.append(md)
}
return marr
}
}
import UIKit
class twoViewController: UIViewController,UITableViewDelegate,UITableViewDataSource {
var marr :[mymodel]=celldata.setcelldata()
override func viewDidLoad() {
super.viewDidLoad()
self.navigationController?.navigationBar.tintColor=UIColor.init(red: 161/256.0, green: 133/256.0, blue: 247/256.0, alpha: 1.0)
self.navigationController?.navigationBar.barTintColor=UIColor.black
//左按钮
let leftbtn = UIBarButtonItem(title: “ASMR”, style: .plain, target: self, action: #selector(leftclick))
self.navigationItem.leftBarButtonItem=leftbtn
let tbv = UITableView(frame: self.view.frame, style: .plain)
tbv.delegate=self
tbv.dataSource=self
self.view .addSubview(tbv)
tbv .register(UINib (nibName: "myViewCell", bundle: Bundle.main), forCellReuseIdentifier: "cell1")
tbv.separatorColor=UIColor.init(red: 161/256.0, green: 133/256.0, blue: 247/256.0, alpha: 1.0)
//表格头视图
let headerview = UIView(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: 220))
tbv.tableHeaderView=headerview
let imgview = UIImageView(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: 150))
imgview.image=UIImage(named: "4")
headerview .addSubview(imgview)
headerview.backgroundColor=UIColor.black
let imgview2 = UIImageView(frame: CGRect(x: 10, y: 170, width: 40, height: 40))
imgview2.image=UIImage(named: "5")
headerview.addSubview(imgview2)
let labb = UILabel(frame: CGRect(x: 60, y: 170, width: 100, height: 50))
labb.text="随机播放"
labb.textColor=UIColor.white
headerview .addSubview(labb)
}
//点击左按钮方法
@objc func leftclick(){
print("这是左按钮")
}
//去掉表格点击效果
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: false)
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return marr.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell:myViewCell=tableView.dequeueReusableCell(withIdentifier: "cell1") as! myViewCell
let md:mymodel=marr[indexPath.row]
cell.setcellwithdata(model: md)
return cell
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 80
}
}