懒加载的写法不止这一个,但是比较喜欢这种写法,里面可以写好多设置
lazy var tab: UITableView? = {
let tempTableView = UITableView (frame: self.view.bounds, style:.plain)
tempTableView.delegate = self
tempTableView.dataSource = self
tempTableView.backgroundColor = UIColor.green
tempTableView.separatorStyle = .singleLine
return tempTableView
}()
外部使用:
view.addSubview(tab!)
tab?.tableFooterView = UIView(frame: CGRect(x: 0, y: 0, width: 0, height: 0))