var mArr:[musicModel] = CellData.getCellData()
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return mArr.count
}
// 在控制器中创建10个model数组
// 给tableView添加数据
// 实现协议方法
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell:ZDYTableViewCell = tableView.dequeueReusableCell(withIdentifier: "cell") as! ZDYTableViewCell
cell.setCellWithData(model: mArr[indexPath.row])
return cell
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 100
}
// 创建tableView
// 创建tabbarHeaderView,添加图片
// 自定义cell
//------------------------------
override func viewDidLoad() {
super.viewDidLoad()
//i标题
self.navigationItem.title = "商品"
self.navigationController?.navigationBar.barTintColor = UIColor.purple
//左按钮
let leftBtn = UIBarButtonItem(title: "哈哈", style: .plain, target: self, action: #selector(leftButton))
self.navigationItem.leftBarButtonItem = leftBtn
//表格
let table = UITableView(frame: self.view.frame, style: .plain)
self.view.addSubview(table)
table.register(UINib (nibName: "ZDYTableViewCell", bundle: nil), forCellReuseIdentifier: "cell")
table.delegate = self
table.dataSource = self
// geicell添加标题,播放次数),播放次数图片),音频时长
let viewHead = UIView(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: 260))
table.tableHeaderView = viewHead
let imgView = UIImageView(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: 200))
viewHead.addSubview(imgView)
imgView.image = UIImage(named: "1")
let imgView1 = UIImageView(frame: CGRect(x: 10, y: 200, width: 60, height: 60))
viewHead.addSubview(imgView1)
imgView1.image = UIImage(named: "1")
let label = UILabel(frame: CGRect(x: 80, y: 200, width: UIScreen.main.bounds.width, height: 60))
viewHead.addSubview(label)
label.text = "随机播放"
}
//按钮
@objc func leftButton() -> Void {
print("点击左键")
}
}