Swift UITableView基础

来源:互联网 发布:amf数据分析器 v22 编辑:程序博客网 时间:2024/06/05 07:13
class DDBaseViewController: UIViewController,UITableViewDelegate,UITableViewDataSource {        var _dataSoure = NSMutableArray()    override func viewDidLoad() {        super.viewDidLoad()        self.view.backgroundColor = UIColor.red                for index in 0...10 {            let title = String(index)            _dataSoure.add(title)        }        let frame = CGRect(x: 0, y: 64, width: self.view.bounds.size.width, height: self.view.bounds.size.height)        let tableView = UITableView(frame: frame, style: .plain)        tableView.delegate = self;        tableView.dataSource = self;        self.view.addSubview(tableView)    }        func numberOfSections(in tableView: UITableView) -> Int {        return 1    }        func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {        return _dataSoure.count    }        func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {        let identifier = "identifierCell"                var cell = tableView.dequeueReusableCell(withIdentifier: identifier)        if cell == nil {           cell = UITableViewCell(style: .default, reuseIdentifier: identifier)        }                cell?.textLabel?.text = String(describing: _dataSoure[indexPath.row])                return cell!    }        func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {            }        override func didReceiveMemoryWarning() {        super.didReceiveMemoryWarning()    }}

原创粉丝点击