swift表格

这篇博客主要介绍了如何使用Swift语言在iOS应用中创建和管理表格视图(UITableView)。通过实现UITableViewDataSource和UITableViewDelegate协议,详细讲解了数据源方法和委托方法的用法。
摘要由CSDN通过智能技术生成

import UIKit

class oneeViewController: UIViewController,UITableViewDataSource,UITableViewDelegate {

    var tabv = UITableView()

    override func viewDidLoad() {
        super.viewDidLoad()
        
        
        self.navigationController?.navigationBar.barTintColor = UIColor .white
        self.view.backgroundColor = UIColor .white
        
        tabv = UITableView(frame: self.view.frame, style: UITableView.Style.grouped)
        
        tabv.delegate = self
        tabv.dataSource = self
        
        self.view.addSubview(tabv)
        
    }

    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        if section == 0 {
            return 2
        }else if section == 1{
            return 3
        }else{
            return 4
        }
    }
    
    func numberOfSections(in tableView: UITableView) -> Int {
        return 3
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cellID = "cell"
        var cell = tableView.dequeueReusableCell(withIdentifier: cellID)
        if cell == nil{
            
            cell = UITableViewCell.init(style: UITableViewCell.CellStyle.value1, reuseIdentifier: cellID)
            
        }
        
        if indexPath.section == 0{
            if indexPath.row == 0{
       
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值