Last active
March 29, 2018 08:52
-
-
Save choiks14/f7ac1f4139099bebf5eb48cba940df71 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
import UIKit | |
import SnapKit | |
/******************************************************************************** | |
1.view 구조 | |
-view | |
-tableView | |
2.extension 구조 | |
(1).init | |
(2).logic | |
(3).data | |
(4).ui | |
(5).event | |
(6).tableview | |
(99).snapkit | |
*********************************************************************************/ | |
/******************************************************************************** | |
1.init | |
*********************************************************************************/ | |
class MainViewController: UIViewController { | |
//setup flag | |
var didSetupConstraints = false | |
//tableView | |
let tableView: UITableView = { | |
let tableView = UITableView() | |
tableView.tableFooterView = UIView() | |
return tableView | |
}() | |
//cell name | |
let cellName: String = "Cell" | |
//tutorial list | |
//var itemList: [Item] = [] | |
//view did load | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
//1.setup ui | |
self.setupUI() | |
//2.init ui | |
self.initUI() | |
//3.init data | |
self.initData() | |
//4.init event | |
self.initEvent() | |
//5.reload data | |
self.tableView.reloadData() | |
} | |
//memory warning | |
override func didReceiveMemoryWarning() { | |
super.didReceiveMemoryWarning() | |
} | |
//did appear | |
override func viewDidAppear(_ animated: Bool) { | |
super.viewDidAppear(animated) | |
} | |
} | |
/******************************************************************************** | |
2.logic | |
*********************************************************************************/ | |
extension MainViewController { | |
//todo logic | |
} | |
/******************************************************************************** | |
3.data | |
*********************************************************************************/ | |
extension MainViewController { | |
//init data | |
func initData() { | |
//todo data | |
} | |
} | |
/******************************************************************************** | |
4.ui | |
*********************************************************************************/ | |
extension MainViewController { | |
//init UI | |
func initUI() { | |
self.initTableView() | |
} | |
//init tableview | |
func initTableView() { | |
self.tableView.dataSource = self | |
self.tableView.delegate = self | |
self.tableView.rowHeight = 50 | |
self.tableView.register(UITableViewCell.self, forCellReuseIdentifier: self.cellName) | |
} | |
} | |
/******************************************************************************** | |
5.event | |
*********************************************************************************/ | |
extension MainViewController { | |
//init event | |
func initEvent() { | |
//todo event | |
} | |
} | |
/******************************************************************************** | |
6.tableview | |
*********************************************************************************/ | |
extension MainViewController: UITableViewDelegate, UITableViewDataSource { | |
//count | |
public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { | |
return 50 | |
} | |
//cell | |
public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { | |
let cell: UITableViewCell = tableView.dequeueReusableCell(withIdentifier: self.cellName) as! UITableViewCell | |
cell.textLabel?.text = "\(indexPath.row)" | |
return cell | |
} | |
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { | |
tableView.deselectRow(at: indexPath, animated: true) | |
} | |
} | |
/******************************************************************************** | |
99.snapkit | |
*********************************************************************************/ | |
extension MainViewController { | |
//setup | |
func setupUI() { | |
self.view.backgroundColor = .white | |
//view | |
self.view.addSubview(self.tableView) | |
//update | |
view.setNeedsUpdateConstraints() | |
} | |
//updateview | |
override func updateViewConstraints() { | |
if (!didSetupConstraints) { | |
//tableView | |
self.tableView.snp.makeConstraints { (make) in | |
make.top.equalTo(self.topLayoutGuide.snp.bottom) | |
make.left.right.equalTo(self.view) | |
make.top.equalTo(self.bottomLayoutGuide.snp.top) | |
} | |
didSetupConstraints = true | |
} | |
super.updateViewConstraints() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment