美文网首页
swift 表格

swift 表格

作者: 你又脸红了i | 来源:发表于2018-12-14 11:03 被阅读0次

    // 屏幕的宽

    let SCREEN_WIDTH = UIScreen.main.bounds.size.width

    // 屏幕的高

    let SCREEN_HEIGHT = UIScreen.main.bounds.size.height

    import UIKit

    class ViewController: UIViewController,UITableViewDelegate, UITableViewDataSource {

        lettableView =UITableView()

        overridefuncviewDidLoad() {

            super.viewDidLoad()

            self.view.backgroundColor = .orange

            lettbv =UITableView(frame:self.view.frame, style: .grouped)

            tbv.backgroundColor = UIColor.white;

            view.addSubview(tbv)

            tbv.dataSource=self

            tbv.delegate=self

        }

        // cell的个数

        functableView(_tableView:UITableView, numberOfRowsInSection section:Int) ->Int{

            return10

        }

        // UITableViewCell

        functableView(_tableView:UITableView, cellForRowAt indexPath:IndexPath) ->UITableViewCell{

            letcellid ="testCellID"

            varcell = tableView.dequeueReusableCell(withIdentifier:"cellid")

            ifcell ==nil{

                cell =UITableViewCell(style: .subtitle, reuseIdentifier: cellid)

            }

            cell?.textLabel?.text="这个是标题~"

            returncell!

        }

        // 设置cell高度

        functableView(_tableView:UITableView, heightForRowAt indexPath:IndexPath) ->CGFloat{

            return60.0

        }

        // 选中cell后执行此方法

        functableView(_tableView:UITableView, didSelectRowAt indexPath:IndexPath) {

            print(indexPath.row)

        }

    }

    相关文章

      网友评论

          本文标题:swift 表格

          本文链接:https://www.haomeiwen.com/subject/lwbwhqtx.html