import UIKit
class UITableViewController: UIViewController ,UITableViewDelegate,UITableViewDataSource{
var tableView = UITableView()
var SectionName:[String] = [];
var rowName1:[String] = []
var rowName2:[String] = []
var rowName3:[String] = []
var rowName4:[String] = []
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
//初始化
SectionName = ["熊大","熊二","熊三","?"]
self.title="周考成绩单";
tableView = UITableView.init(frame: self.view.frame, style: .plain);
tableView.delegate=self;
tableView.dataSource=self;
self.view.addSubview(tableView)
}
func numberOfSections(in tableView: UITableView) -> Int {
return SectionName.count
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
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
}
}
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return 50
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let str = "x"
var cell = tableView.dequeueReusableCell(withIdentifier: str)
if cell == nil{
cell = UITableViewCell.init(style: .subtitle, reuseIdentifier: str)
}
//
if indexPath.section==0 {
cell?.textLabel?.text=rowName1[indexPath.row]
}else if indexPath.section==1 {
cell?.textLabel?.text=rowName2[indexPath.row]
}else if indexPath.section==2 {
cell?.textLabel?.text=rowName3[indexPath.row]
}else if indexPath.section==3 {
cell?.textLabel?.text=rowName4[indexPath.row]
}else
{
}
return cell!
}
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
//页眉标题
let vw = UIView.init(frame: CGRect.init(x: 0, y: 10, width: UIScreen.main.bounds.width, height: 50))
vw.backgroundColor=UIColor.green
let lb = UILabel.init(frame: CGRect.init(x: 50, y: 5, width: 100, height: 40))
lb.text=SectionName[section];
//录入分数
let btn = UIButton.init(frame: CGRect.init(x: 300, y: 5, width: 100, height: 40))
btn.setTitle("录入分数", for: UIControl.State.normal)
btn.addTarget(self, action: #selector(click), for: UIControl.Event.touchUpInside)
btn.setTitleColor(UIColor.red, for: UIControl.State.normal)
btn.tag = section + 100
vw.addSubview(btn)
vw.addSubview(lb)
return vw
}
@objc func click(but:UIButton){
print(but.tag)
let tiao = fenshu()
tiao.jumpScore = {
(String1,String2,String3)->()in
switch but.tag {
case 100:
self.rowName1.removeAll()
self.rowName1.append("语文:\(String1)")
self.rowName1.append("数学:\(String2)")
self.rowName1.append("英语:\(String3)")
case 101:
self.rowName2.removeAll()
self.rowName2.append("语文:\(String1)")
self.rowName2.append("数学:\(String2)")
self.rowName2.append("英语:\(String3)")
case 102:
self.rowName3.removeAll()
self.rowName3.append("语文:\(String1)")
self.rowName3.append("数学:\(String2)")
self.rowName3.append("英语:\(String3)")
case 103:
self.rowName4.removeAll()
self.rowName4.append("语文:\(String1)")
self.rowName4.append("数学:\(String2)")
self.rowName4.append("英语:\(String3)")
default:
""
}
self.tableView.reloadData()
}
self.navigationController?.pushViewController(tiao, animated: true)
}
}
class fenshu: UIViewController {
typealias block = (String,String,String)->()//闭包默认
var jumpScore : block?
@IBOutlet weak var tf1: UITextField!
@IBOutlet weak var tf2: UITextField!
@IBOutlet weak var tf3: UITextField!
//两个按钮
@IBAction func save() {
self.jumpScore!(tf1.text!,tf2.text!,tf3.text!)
self.navigationController?.popViewController(animated: true)
}
@IBAction func quxiao(_ sender: Any) {
self.navigationController?.popViewController(animated: true)
}