import UIKit
var tableview = UITableView()
let cellid = "cell"
var tableData = NSMutableArray()
let sizeView = UIScreen.main.bounds.size
class TableviewViewController: UIViewController,UITableViewDelegate,UITableViewDataSource {
override func viewDidLoad() {
super.viewDidLoad()
self.creatUI()
// Do any additional setup after loading the view.
}
func creatUI() {
self.title = "TableView"
self.view.backgroundColor = UIColor.white
tableview.frame = CGRect(x: 0, y: 20, width:sizeView.width, height: sizeView.height-20)
tableview.delegate = self
tableview.dataSource = self
self.view .addSubview(tableview)
for i in 1...66 {
tableData.add("siwft\(i)")
}
tableview.reloadData()
}
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return tableData.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
var cell = tableView.dequeueReusableCell(withIdentifier: cellid)
if cell == nil {
cell = UITableViewCell (style: UITableViewCellStyle.default, reuseIdentifier: cellid)
cell?.selectionStyle = UITableViewCellSelectionStyle.none
}
cell!.tintColor = UIColor.red
cell!.textLabel?.text = tableData[indexPath.row] as! String
return cell!
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
self.present(CollectionViewController(), animated: true) {
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}