@@ -10,41 +10,55 @@ import UIKit
1010import TinyConsole
1111
1212class MainViewController : UITableViewController {
13- override func viewDidLoad( ) {
14- super. viewDidLoad ( )
15- self . view. backgroundColor = UIColor . white
16-
17- self . tableView. register ( UITableViewCell . self, forCellReuseIdentifier: " default " )
18-
19- self . navigationItem. leftBarButtonItem = UIBarButtonItem ( title: " Add Log " , style: UIBarButtonItemStyle . plain, target: self , action: #selector( addLog) )
20- self . navigationItem. rightBarButtonItems = [
21- UIBarButtonItem ( title: " Add Marker " , style: UIBarButtonItemStyle . plain, target: self , action: #selector( addMarker) ) ,
22- UIBarButtonItem ( title: " Clear " , style: UIBarButtonItemStyle . plain, target: self , action: #selector( clear) ) ,
23- ]
24- }
13+ var tableViewDelegate : UITableViewDelegate
14+ var tableViewDataSource : UITableViewDataSource
2515
26- override func numberOfSections( in tableView: UITableView ) -> Int {
27- return 1
16+ init ( ) {
17+ tableViewDelegate = MainTableViewDelegate ( )
18+ tableViewDataSource = MainTableViewDataSource ( )
19+ super. init ( style: UITableViewStyle . plain)
2820 }
2921
30- override func tableView ( _ tableView : UITableView , numberOfRowsInSection section : Int ) -> Int {
31- return 30
22+ required init ? ( coder aDecoder : NSCoder ) {
23+ fatalError ( " init(coder:) has not been implemented " )
3224 }
3325
34- override func tableView( _ tableView: UITableView , cellForRowAt indexPath: IndexPath ) -> UITableViewCell {
35- let cell = self . tableView. dequeueReusableCell ( withIdentifier: " default " , for: indexPath)
26+ override func viewDidLoad( ) {
27+ ( tableViewDataSource as? MainTableViewDataSource ) ? . registerCellsForTableView ( self . tableView)
28+ tableView. delegate = tableViewDelegate
29+ tableView. dataSource = tableViewDataSource
3630
37- cell. textLabel? . text = " Row \( indexPath. row) "
31+ super. viewDidLoad ( )
32+ view. backgroundColor = UIColor . white
3833
39- return cell
34+ setupNavigationItems ( )
4035 }
41-
42- override func tableView( _ tableView: UITableView , didSelectRowAt indexPath: IndexPath ) {
43- TinyConsole . print ( " Tapped on \( indexPath. row) " )
36+
37+ override func viewDidAppear( _ animated: Bool ) {
38+ super. viewDidAppear ( animated)
39+
40+ TinyConsole . print ( " Welcome to TinyConsole " )
41+ TinyConsole . addMarker ( )
42+ TinyConsole . print ( " NOW " , color: UIColor . red)
43+ TinyConsole . print ( " IN " , color: UIColor . green)
44+ TinyConsole . print ( " COLOR " , color: UIColor . blue)
45+ TinyConsole . addMarker ( )
4446 }
4547
48+ func setupNavigationItems( ) {
49+ navigationItem. leftBarButtonItems = [
50+ UIBarButtonItem ( title: " Add Log " , style: UIBarButtonItemStyle . plain, target: self , action: #selector( addLog) )
51+ ]
52+ navigationItem. rightBarButtonItems = [
53+ UIBarButtonItem ( title: " Add Marker " , style: UIBarButtonItemStyle . plain, target: self , action: #selector( addMarker) ) ,
54+ UIBarButtonItem ( title: " Clear " , style: UIBarButtonItemStyle . plain, target: self , action: #selector( clear) ) ,
55+ ]
56+ }
57+ }
58+
59+ extension MainViewController {
4660 func addLog( ) {
47- TinyConsole . print ( " hello world " )
61+ TinyConsole . print ( " Hello World " )
4862 }
4963
5064 func clear( ) {
@@ -55,4 +69,3 @@ class MainViewController: UITableViewController {
5569 TinyConsole . addMarker ( )
5670 }
5771}
58-
0 commit comments