@objcfuncAdd1() {
self.navigationController?.popViewController(animated:true)
NotificationCenter.default.post(name:NSNotification.Name(rawValue:"s"), object:nil, userInfo: ["one":textfildy.text!,"two":textfilds.text!,"three":textfilde.text!])
}
@objcfuncAdd2() {
self.navigationController?.popViewController(animated:true)
}
import UIKit
class HomeViewController: UIViewController,UITableViewDelegate,UITableViewDataSource {
vartableView =UITableView()
overridefuncviewDidLoad() {
super.viewDidLoad()
self.title="首页"
self.view.backgroundColor = UIColor.lightGray
//在第一个子控制器上添加一个不分区的UITableView子视图
tableView=UITableView(frame:UIScreen.main.bounds, style: .plain)
tableView.delegate=self
tableView.dataSource=self
self.view.addSubview(tableView)
self.tableView.register(UINib(nibName:"ZDYTableViewCell", bundle:nil), forCellReuseIdentifier:"cell")
}
functableView(_tableView:UITableView, numberOfRowsInSection section:Int) ->Int{
return10
}
functableView(_tableView:UITableView, heightForRowAt indexPath:IndexPath) ->CGFloat{
return70
}
functableView(_tableView:UITableView, didSelectRowAt indexPath:IndexPath) {
//输出
print("点击了第\(indexPath.row)个单元格")
tableView.deselectRow(at: indexPath, animated:true)
}
functableView(_tableView:UITableView, cellForRowAt indexPath:IndexPath) ->UITableViewCell{
varcell = tableView.dequeueReusableCell(withIdentifier:"cell")
ifcell ==nil{
cell =ZDYTableViewCell.init(style: .default, reuseIdentifier:"cell")
}
cell!.backgroundColor=UIColor.init(red:CGFloat(arc4random()%256)/255.0, green:CGFloat(arc4random()%256)/255.0, blue:CGFloat(arc4random()%256)/255.0, alpha:1);
returncell!
}
}
letlab =UILabel()
vartextfildy =UITextField()
letlab1 =UILabel()
vartextfilds =UITextField()
letlab2 =UILabel()
vartextfilde =UITextField()
overridefuncviewDidLoad() {
super.viewDidLoad()
self.view.backgroundColor=UIColor.white
letlab =UILabel(frame:CGRect(x:80, y:110, width:40, height:20))
lab.text="语文:"
lab.textColor=UIColor.black
self.view.addSubview(lab)
textfildy=UITextField(frame:CGRect(x:120, y:100, width:200, height:40))
textfildy.backgroundColor=UIColor.green
textfildy.placeholder="输入成绩"
self.view.addSubview(textfildy)
letlab1 =UILabel(frame:CGRect(x:80, y:160, width:40, height:20))
lab1.text="数学:"
lab1.textColor=UIColor.black
self.view.addSubview(lab1)
textfilds=UITextField(frame:CGRect(x:120, y:150, width:200, height:40))
textfilds.backgroundColor=UIColor.red
textfilds.placeholder="输入成绩"
self.view.addSubview(textfilds)
letlab2 =UILabel(frame:CGRect(x:80, y:210, width:40, height:20))
lab2.text="英语:"
lab2.textColor=UIColor.black
self.view.addSubview(lab2)
textfilde=UITextField(frame:CGRect(x:120, y:200, width:200, height:40))
textfilde.backgroundColor=UIColor.yellow
textfilde.placeholder="输入成绩"
self.view.addSubview(textfilde)
letbut =UIButton(frame:CGRect(x:80, y:250, width:40, height:20))
but .setTitle("保存", for: .normal)
but .addTarget(self, action:#selector(Add1), for:.touchUpInside)
but .setTitleColor(UIColor.red, for:.normal)
self.view.addSubview(but)
letbut1 =UIButton(frame:CGRect(x:310, y:250, width:40, height:20))
but1 .setTitle("返回", for: .normal)
but1 .addTarget(self, action:#selector(Add2), for:.touchUpInside)
but1 .setTitleColor(UIColor.red, for:.normal)
self.view.addSubview(but1)
}
@objcfuncAdd1() {
self.navigationController?.popViewController(animated:true)
NotificationCenter.default.post(name:NSNotification.Name(rawValue:"s"), object:nil, userInfo: ["one":textfildy.text!,"two":textfilds.text!,"three":textfilde.text!])
}
@objcfuncAdd2() {
self.navigationController?.popViewController(animated:true)
}
}
functableView(_tableView:UITableView, cellForRowAt indexPath:IndexPath) ->UITableViewCell{
varcell = tableView.dequeueReusableCell(withIdentifier:"cell")
ifcell ==nil{
cell =UITableViewCell.init(style: .default, reuseIdentifier:"cell")
}
ojtable?.rowHeight=60
letarr1 = ["隆佳佳","王克扬","张继良","俄罗斯"]
letlb1 =UILabel(frame:CGRect(x:20, y:10, width:200, height:40))
lb1.text= arr1[indexPath.row]
cell?.addSubview(lb1)
//按钮
letbtn1 =UIButton(frame:CGRect(x:260, y:10, width:100, height:40))
btn1.setTitle("详情", for: .normal)
btn1.tintColor = UIColor.yellow
btn1.backgroundColor = UIColor.red
//按钮的点击方法
btn1.addTarget(self, action:#selector(els1), for: .touchUpInside)
cell?.addSubview(btn1)
returncell!
}
@objcfuncels1(){
let o = oneViewController()
self.navigationController?.pushViewController(o, animated:true)
}
}