美文网首页
swift-13tableView

swift-13tableView

作者: sunmumu1222 | 来源:发表于2017-08-30 09:05 被阅读4次

    我以前做的swift笔记, 之前都是整理在onenote上, 最近想到整理出博客. 也方便自己查找, 可以当做自己的一份文档.

    import UIKit
    
    class ViewController: UIViewController, UITableViewDataSource {
    
        override func viewDidLoad() {
            super.viewDidLoad()
            setupUI()
        }
        
        func setupUI() {
            //1创建
            let tv = UITableView(frame: view.bounds, style: .plain)
            //2添加
            view.addSubview(tv)
            //3注册可重用
            tv.register(UITableViewCell.self, forCellReuseIdentifier: "cellID")
            
            //4设置数据源
            tv.dataSource = self
        }
        
        // MARK: - UITableViewDataSource
        func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
            return 20
        }
        
        func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
            let cell = tableView.dequeueReusableCell(withIdentifier: "cellID")
            cell?.textLabel?.text = "hello ~~~~ \(indexPath.row)"
            return cell!
            
        }
        
    
        override func didReceiveMemoryWarning() {
            super.didReceiveMemoryWarning()
            // Dispose of any resources that can be recreated.
        }
    
    
    }
    

    相关文章

      网友评论

          本文标题:swift-13tableView

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