Swift --**表格书写**

Swift –表格书写

第一步定义表格 这里 swift的初始化与oc不太一样 但是思想是一样的

全局变量
var tableView:UITableView?
//设置表格的位置大小 代理 重中之重就是表格的代理协议

<UITableViewDelegate,UITableViewDataSource>

self.tableView=UITableView(frame: self.view.frame,style:.grouped )
//代理
tableView?.delegate=self
tableView?.dataSource=self
//添加表格
self.view .addSubview(self.tableView!)

    //创建一个重用的单元格  //注册
    self.tableView!.register(UITableViewCell.self,
                             forCellReuseIdentifier: "SwiftCell")

单元格方法中的 与上边注册迎合复用

//单元格返回行数
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

}

//单元格内容书写方法
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
//为了提供表格显示性能,已创建完成的单元需重复使用
let identify:String = “SwiftCell”
//同一形式的单元格重复使用,在声明时已注册
let cell = tableView.dequeueReusableCell(withIdentifier: identify, for: indexPath)
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值