传值

作者: 小美788 | 来源:发表于2018-11-22 20:21 被阅读0次

 @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)

    }

}

相关文章

  • iOS的五种传值

    前言 iOS常见的五种传值分别为属性传值,通知传值,代理传值,block传值,单例传值 属性传值 用于正向传值,简...

  • 页面传值-03

    一、传值分类 页面传值基本分为两种:正向传值和反向传值。 二、传值方式 传值,最基本的无非就是代理传值、通知传值、...

  • iOS 页面(代理、通知、block、单例、属性)传值

    一、传值分类 页面传值基本分为两种:正向传值和反向传值。 二、传值方式 传值,最基本的无非就是代理传值、通知传值、...

  • iOS-传值方式

    传值方式:1、属性传值 方法传值2、代理传值3、单例传值 4、通知传值 NSNotificationCente...

  • Swift常用的界面传值(属性传值、协议传值、闭包传值)

    1、属性传值 属性传值多用于正向传值(A->B) 2、代理传值 代理传值多用于反向传值(B->A) 3、闭包传值 ...

  • Vue组件间关系及六种传值方式

    前言: 六种传值方式为: 属性传值 $refs $parent 通知传值(广播传值) 本地传值 路由传值 在介绍组...

  • 【iOS开发细节】之- delegate代理的使用

    在iOS开发中、好多时候需要涉及到页面传值、而传值又分为正向传值和反向传值 一、 传值 1、正向传值 2、反向传值...

  • reactNative 之组件传值和反向传值

    在项目中我们经常会遇到传值,传值有正向传值和反向传值,比如1.正向传值:从A组件push到B组件传值2.反向传值:...

  • 代理

    不同页面间传值是必不可少,传值的方式有很多(方法传值,属性传值,代理传值,单例传值) ,这里主要总结下属性传值和代...

  • ios常用的三种传值方式

    iOS中有多种方案可以实现页面之间的传值,例如:属性传值、代理传值、block传值、单例传值...。常用的三种传值...

网友评论

      本文标题:传值

      本文链接:https://www.haomeiwen.com/subject/btetiftx.html