import UIKit
class TwoVC: UIViewController,UITableViewDelegate,UITableViewDataSource {
var mArr:[musicModel] = CellData.getCellData()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
self.view.backgroundColor = UIColor.white
self.navigationItem.title = "商品"
self.navigationController?.navigationBar.barTintColor = UIColor.purple
let leftBtn = UIBarButtonItem(title: "back", style: .plain, target: self, action: #selector(leftButton))
self.navigationItem.leftBarButtonItem = leftBtn
let tv = UITableView(frame: self.view.frame, style: .plain)
self.view.addSubview(tv)
tv.delegate = self
tv.dataSource = self
tv.register(UINib(nibName: "MusicCell", bundle: Bundle.main), forCellReuseIdentifier: "Cell1")
let viewHead = UIView(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: 150))
tv.tableHeaderView = viewHead
let imgView = UIImageView(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: 150))
viewHead.addSubview(imgView)
imgView.image = UIImage(named: "1")
let viewBack = UIView(frame: CGRect(x: 0, y: viewHead.frame.size.height-60, width: UIScreen.main.bounds.width, height: 60))
viewHead.addSubview(viewBack)
viewBack.backgroundColor = UIColor.lightGray
let imgHead = UIImageView(frame: CGRect(x: 20, y: (viewBack.frame.size.height-40)/2, width: 40, height: 40))
viewBack.addSubview(imgHead)
imgHead.image = UIImage(named: "1")
let title = UILabel(frame: CGRect(x: 20+imgHead.frame.size.width+5, y: (viewBack.frame.size.height-40)/2, width: 150, height: 40))
viewBack.addSubview(title)
title.text = "速记播放"
}
@objc func leftButton() -> Void {
print("点击左键")
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return mArr.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell:MusicCell = tableView.dequeueReusableCell(withIdentifier: "Cell1") as! MusicCell
let md:musicModel = mArr[indexPath.row]
cell.setCellWithData(model: md)
return cell
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 100
}
}
Swift表格调用model
最新推荐文章于 2023-07-05 11:15:22 发布