-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathViewController.swift
More file actions
72 lines (49 loc) · 2.17 KB
/
Copy pathViewController.swift
File metadata and controls
72 lines (49 loc) · 2.17 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
//
// ViewController.swift
// KindleAppRemake
//
// Created by Anthony Aoun on 2018-04-14.
// Copyright © 2018 Anthony Aoun. All rights reserved.
//
import UIKit
class ViewController: UITableViewController {
var books: [Book]?
override func viewDidLoad() {
super.viewDidLoad()
tableView.register(BookCell.self, forCellReuseIdentifier: "cellId")
tableView.tableFooterView = UIView()
navigationItem.title = "Kindle Remake"
setupBooks()
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
guard let unwrappedBookCount = books?.count else {
return 0
}
return unwrappedBookCount
}
override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 80
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cellId", for: indexPath)
let book = books?[indexPath.row]
cell.textLabel?.text = book?.title
cell.imageView?.image = book?.image
return cell
}
func setupBooks(){
let page1 = Page(number: 1, text: "this is the first page text")
let page2 = Page(number: 2, text: "this is the second page text")
let pages1 = [page1, page2]
let book = Book(title: "Steve Jobs", author: "Waler Thomas", image: #imageLiteral(resourceName: "steve_jobs"), pages: pages1)
let book2 = Book(title: "Bill Gates: A Biography", author: "Michael Becraft", image: #imageLiteral(resourceName: "bill_gates"), pages: [
Page(number: 1, text: "Text for page 1"),
Page(number: 2, text: "Text for page 2"),
Page(number: 3, text: "Text for page 3"),
Page(number: 4, text: "Text for page 4"),
Page(number: 5, text: "Text for page 4"),
Page(number: 6, text: "Text for page 5")
])
self.books = [book, book2]
}
}