[swift] tableViewController Template
Here is template for tableViewController
on Storyboard, ViewController + TableView + TableViewCell should be setup
on TableViewCell, setup “tableCell” as ID
import UIKit
class testTableViewContoller: UIViewController, UITableViewDelegate, UITableViewDataSource{
@IBOutlet weak var tableView: UITableView!
let array:[String] = ["swift","Ruby","Rails","PHP","HTML.CSS","JS","Java"]
override func viewDidLoad() {
super.viewDidLoad()
// Delegate Setting
tableView.dataSource = self
tableView.delegate = self
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// Amount of Cell for 1 section
return array.count
}
func numberOfSections(in tableView: UITableView) -> Int {
// Amount of Section
return 1
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
// Cell Height
return 50
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
// Cell Detail Setting
let cell = tableView.dequeueReusableCell(withIdentifier: "tableCell", for: indexPath)
cell.textLabel?.text = array[indexPath.row]
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
//Selected Method
}
}