ViewController 简单常用的内部结构
import UIKit
class ViewController: UIViewController {
//MARK: - Property 属性
var str:String?
var button = UIButton()
var tableView = UITableView()
//MARK: - LifeCycle 生命周期
override func viewDidLoad() {
super.viewDidLoad()
}
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
}
//MARK: - ViewSetup 视图设置
func setupNavigationBar() {
//navigationItem.title = ""
}
func addSubview() {
self.view.addSubview(button)
self.view.addSubview(tableView)
}
func setupLayout() {
button.frame = CGRect(x: 0, y: 0, width: 20, height: 20)
tableView.frame = CGRect(x: 0, y: 0, width: self.view.bounds.width, height: self.view.bounds.height)
//注意:如果使用snapKit布局,snp_makeConstraints 方法的元素必须事先添加到父元素的中,例如:self.view.addSubview(view)
}
func setupSubviews() {
//button.enabled = false
tableView.delegate = self
tableView.dataSource = self
}
//MARK: - private 内部方法
func getDataFromServer() {
//加载数据
}
func handleData() {
//处理数据
}
}
//MARK: - Delegate
extension ViewController: UITableViewDelegate, UITableViewDataSource {
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 6
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
return UITableViewCell()
}
}