1 import UIKit
2
3 class ViewController:UIViewController,
UITableViewDataSource, UITableViewDelegate {
4
5 override func viewDidLoad() {
6 super.viewDidLoad()
7 // Do any additional setup after loading the view,
typically from a nib.
8
9 let screenRect = UIScreen.main.bounds
10 let tableRect = CGRect(x:0, y:20, width:
screenRect.size.width, height:screenRect.size.height - 20)
11 let tableView = UITableView(frame:tableRect)
12
13 tableView.dataSource = self
14 tableView.delegate = self
15
16 self.view.addSubview(tableView)
17 }
18
19 func tableView(_ tableView:UITableView,
heightForRowAt indexPath:IndexPath) -> CGFloat {
20 if (indexPath as NSIndexPath).row % 2 == 0
21 {
22 return 104;
23 }
24 return 40;
25 }
26
27 func tableView(_ tableView:UITableView,
numberOfRowsInSection section:Int) -> Int{
28 return 20
29 }
30
31 func tableView(_ tableView:UITableView,cellForRowAt indexPath:IndexPath) -> UITableViewCell {
32
33 let identifier = “reusedCell”
34 var cell =
tableView.dequeueReusableCell(withIdentifier:identifier)
35
36 if(cell == nil)
37 {
38 cell = UITableViewCell(style:
UITableViewCellStyle.default, reuseIdentifier:identifier)
39 }
40 if (indexPath as NSIndexPath).row % 2 == 0
41 {
42 cell?.imageView?.image =
UIImage(named:“picture.png”)
43 }
44 else
45 {
46 cell?.textLabel?.text = “每有会意,便欣然忘食!”
47 }
48
49 return cell!
50 }
51 }
//UITableViewDelegate