-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathViewController.swift
More file actions
51 lines (37 loc) · 1.24 KB
/
ViewController.swift
File metadata and controls
51 lines (37 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//
// ViewController.swift
// SwiftTableView
//
// Created by Think on 2016/8/20.
// Copyright © 2016年 Think. All rights reserved.
//
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let tableView = UITableView()
tableView.delegate = self
tableView.dataSource = self
view = tableView
}
lazy var listData:[String]? = {
return ["one","two","three","four","five","six"];
}();
}
extension ViewController : UITableViewDataSource,UITableViewDelegate
{
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return (listData?.count)!
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
var cell = tableView.dequeueReusableCell(withIdentifier: "cell")
if cell == nil {
cell = UITableViewCell(style: UITableViewCellStyle.default, reuseIdentifier: "cell")
}
cell?.textLabel?.text = listData![indexPath.row];
return cell!
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
print(listData![indexPath.row])
}
}