swift表格按钮

class CQ_CommunViewController: UIViewController,UITableViewDelegate,UITableViewDataSource {
//------------------------------

// 创建一个musicModel
// 添加title、pic、number、time等属性

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("点击左键")
}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值