import UIKit
class TableVC: UITableViewController {
var sectionName:[String] = []
var rowName1:[String] = []
var rowName2:[String] = []
var rowName3:[String] = []
var rowName4:[String] = []
var cellNum:Int = 0
override func viewDidLoad() {
super.viewDidLoad()
self.navigationItem.title = "业绩单"
sectionName = ["A","B","C","D"]
self.tableView.delegate = self
self.tableView.dataSource = self
self.tableView.tableFooterView = UIView()
self.navigationItem.leftBarButtonItem = UIBarButtonItem(title: "全部", style: .plain, target: self, action: #selector(whole))
}
@objc func whole() {
if rowName1.count>0{
print(" A:\(rowName1[0]),\(rowName1[1]),\(rowName1[2])")
}
if rowName2.count>0{
print("B:\(rowName2[0]),\(rowName2[1]),\(rowName2[2])")
}
if rowName3.count>0{
print("C:\(rowName3[0]),\(rowName3[1]),\(rowName3[2])")
}
if rowName4.count>0{
print("D:\(rowName4[0]),\(rowName4[1]),\(rowName4[2])")
}
}
// MARK: - Table view data source
override func numberOfSections(in tableView: UITableView) -> Int {
// #warning Incomplete implementation, return the number of sections
return sectionName.count
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of rows
switch section {
case 0:
return rowName1.count
case 1:
return rowName2.count
case 2:
return rowName3.count
case 3:
return rowName4.count
default:
return 0
}
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
var cell:UITableViewCell! = tableView.dequeueReusableCell(withIdentifier: "cell")
if cell==nil{
cell = UITableViewCell(style: .default, reuseIdentifier: "cell")
}
// Configure the cell...
switch indexPath.section {
case 0:
cell.textLabel?.text = rowName1[indexPath.row]
case 1:
cell.textLabel?.text = rowName2[indexPath.row]
case 2:
cell.textLabel?.text = rowName3[indexPath.row]
case 3:
cell.textLabel?.text = rowName4[indexPath.row]
default:
""
}
return cell!
}
// override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
//
// return sectionName[section]
// }
override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 80
}
override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let view = UIView(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: 50))
view.backgroundColor = UIColor.lightGray
let btn = UIButton(frame: CGRect(x:UIScreen.main.bounds.width-80-10, y: 10, width: 80, height: 30))
btn.setTitle("录入分数", for: .normal)
btn.addTarget(self, action: #selector(buton), for: .touchUpInside)
btn.setTitleColor(UIColor.red, for: .normal)
view.addSubview(btn)
btn.tag = 100+section
let label = UILabel(frame: CGRect(x: 10, y: 10, width: 60, height: 30))
view.addSubview(label)
label.text = sectionName[section]
let lineView = UIView(frame: CGRect(x: 0, y: 49, width: UIScreen.main.bounds.width, height: 1))
view.addSubview(lineView)
lineView.backgroundColor = UIColor.black
return view
}
override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return 50
}
@objc func buton(but:UIButton){
print(but.tag)
let vc = ScoreWriteVC()
vc.jumpScore = {
(str1,str2,str3)->() in
switch but.tag {
case 100:
self.rowName1.removeAll()
self.rowName1.append("文:\(str1)")
self.rowName1.append("学:\(str2)")
self.rowName1.append("语:\(str3)")
case 101:
self.rowName2.removeAll()
self.rowName2.append("文:\(str1)")
self.rowName2.append("学:\(str2)")
self.rowName2.append("语:\(str3)")
case 102:
self.rowName3.removeAll()
self.rowName3.append("文:\(str1)")
self.rowName3.append("学:\(str2)")
self.rowName3.append("语:\(str3)")
case 103:
self.rowName3.removeAll()
self.rowName3.append("文:\(str1)")
self.rowName3.append("学:\(str2)")
self.rowName3.append("语:\(str3)")
default:
""
}
self.tableView.reloadData()
}
self.navigationController?.pushViewController(vc, animated: true)
}
/*
// Override to support conditional editing of the table view.
override func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
// Return false if you do not want the specified item to be editable.
return true
}
*/
/*
// Override to support editing the table view.
override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
if editingStyle == .delete {
// Delete the row from the data source
tableView.deleteRows(at: [indexPath], with: .fade)
} else if editingStyle == .insert {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
}
}
*/
/*
// Override to support rearranging the table view.
override func tableView(_ tableView: UITableView, moveRowAt fromIndexPath: IndexPath, to: IndexPath) {
}
*/
/*
// Override to support conditional rearranging of the table view.
override func tableView(_ tableView: UITableView, canMoveRowAt indexPath: IndexPath) -> Bool {
// Return false if you do not want the item to be re-orderable.
return true
}
*/
/*
// 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.destination.
// Pass the selected object to the new view controller.
}
*/
}