the code is as follows
Click to highlight, but do not follow the didSelectRowAt indexPath method.
//
// menuViewController.swift
// record
//
// Created by on 2018/5/26.
// Copyright 2018 . All rights reserved.
//
import UIKit
class MenuViewController: UIViewController ,UITableViewDataSource, UITableViewDelegate{
var table:UITableView!
let bgColor = UIColor.init(red: 45/255, green: 50/255, blue: 53/255, alpha: 1)
let arry:[String] = ["", "2", "3"]
var changeView:changeViewDelegate? = nil
override func viewDidLoad() {
super.viewDidLoad()
self.view.backgroundColor = bgColor
self.setUpLayout()
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func setUpLayout(){
let rect = self.view.frame
self.table = UITableView(frame: CGRect(x: 0, y: 63, width: rect.width, height: rect.height-62))
self.table.backgroundColor = bgColor
self.table.dataSource = self
self.table.separatorStyle = UITableViewCellSeparatorStyle.none
self.table.rowHeight = 100
self.table.allowsSelection = true;
self.view.addSubview(self.table)
}
func rowChangeView() {
print("adf")
}
//
//cell
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return arry.count
}
//section
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
return true
}
public func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath){
print("indexPath.row = SelectRow\(indexPath.row)")
}
//tableviewcell
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let rect = self.view.frame
let cell = UITableViewCell.init(frame: CGRect(x: 0, y: 0, width: rect.width, height: 100))
cell.backgroundColor = bgColor
let indexLabel = UILabel.init(frame: CGRect(x: 23, y: 16, width: rect.width, height: 20))
indexLabel.textColor = UIColor.white
indexLabel.text = arry[indexPath.row]
cell.addSubview(indexLabel)
return cell
}
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}
*/
}