成绩单一

class MyUITableViewController: UITableViewController{
var IDD = type(of: 0)
var label1:String=""
var label2:String=""
var label3:String=""
var ss:String?
var DataSoure1:[String] = []
var DataSoure2:[String] = []
var DataSoure3:[String] = []
var nameArr:NSArray = [“杨” , “刘” , “宋”]
// var nameCell = AnyObject
override func viewDidLoad() {
super.viewDidLoad()
self.title = “成绩单”
NotificationCenter.default.addObserver(self, selector: #selector(upDataChange(notif:)), name: NSNotification.Name(rawValue: “s”), object:nil )
self.navigationItem.rightBarButtonItem = UIBarButtonItem.init(title: “录入分数”, style: .done, target: self, action: #selector(rightBtn))
self.tableView .reloadData()
}
//right--------
@objc func rightBtn(){
print(“打印任意信息”)
}
//upDataChange-----
@objc func upDataChange(notif: NSNotification){
self.label1 = (notif.userInfo![“one”] as? String)!
self.label2 = (notif.userInfo![“two”] as? String)!
self.label3 = (notif.userInfo![“three”] as? String)!
var btntag = (notif.userInfo![“tag”] as? Int)
switch btntag {
case 100:
DataSoure1 .removeAll()
DataSoure1 .append(“语:(label1)”)
DataSoure1 .append(“英:(label2)”)
DataSoure1 .append(“数:(label3)”)
case 101:
DataSoure2 .removeAll()
DataSoure2 .append(“语:(label1)”)
DataSoure2 .append(“英:(label2)”)
DataSoure2 .append(“数:(label3)”)
case 102:
DataSoure3 .removeAll()
DataSoure3 .append(“语:(label1)”)
DataSoure3 .append(“英:(label2)”)
DataSoure3 .append(“数:(label3)”)
default:
“”
}
self.tableView .reloadData()
}
@objc func AddBtn1(bbb:UIButton){
var fen = EnteringGradeViewController()
fen.btnTag = bbb.tag
self.navigationController?.pushViewController(fen, animated: true)
}
//分组--------
override func numberOfSections(in tableView: UITableView) -> Int {
return 3
}
//分行-----------
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

    switch section {
    case 0:
        return DataSoure1.count
    case 1:
        return DataSoure2.count
    case 2:
        return DataSoure3.count
    default:
        return 0
    }
}
//行内容---------
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    var cell = tableView .dequeueReusableCell(withIdentifier: "cell")
    
    if !(cell != nil){
        cell = UITableViewCell(style: .subtitle, reuseIdentifier: "cell")
    }
    switch indexPath.section {
    case 0:
        cell?.textLabel?.text = DataSoure1[indexPath.row]
    case 1:
        cell?.textLabel?.text = DataSoure2[indexPath.row]
    case 2:
        cell?.textLabel?.text = DataSoure3[indexPath.row]
    default:
        ""
    }
    
    return cell!
}
//头视图高
override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
    return 30
}
//头视图
override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
    
    let headerView = UIView(frame: CGRect(x: 0, y: 0, width: self.view.frame.size.width, height: 30))
    headerView.backgroundColor = UIColor .lightGray
    //学生姓名
    let StudentName = UILabel(frame: CGRect(x: 10, y: 2, width: 100, height: 30))
    StudentName.text = nameArr[section] as! String
    StudentName.textColor = UIColor .black
    //录入成绩按钮
    let EnteringBtn = UIButton(frame: CGRect(x: 300, y: 2, width: 100, height: 30))
    EnteringBtn .setTitle("录入成绩", for: .normal)
    EnteringBtn .setTitleColor(UIColor .black, for: .normal)
    EnteringBtn .addTarget(self, action: #selector(AddBtn1(bbb:)), for: .touchUpInside)
    EnteringBtn.tag = 100+section
    headerView.addSubview(EnteringBtn)
    headerView.addSubview(StudentName)
    return headerView
    
}
override func viewWillAppear(_ animated: Bool) {
    self.tableView .reloadData()
}

}


版权声明:本文为RjLoveGyh原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。