加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

swift的protocol

发布时间:2020-12-14 01:31:16 所属栏目:百科 来源:网络整理
导读:新建一个Protocol.swift文件 里面的内容 为 import Foundation protocol ChangeTextDelegate{ func changeLableValue(newString:String) } class OtherVC: UIViewController { var delegate : ChangeTextDelegate? override func viewDidLoad() { super.viewD
新建一个Protocol.swift文件 里面的内容 为

import Foundation


protocol ChangeTextDelegate{

func changeLableValue(newString:String)

}


class OtherVC: UIViewController {

var delegate : ChangeTextDelegate?

override func viewDidLoad() {

super.viewDidLoad()

// Do any additional setup after loading the view.

}

override func didReceiveMemoryWarning() {

super.didReceiveMemoryWarning()

// Dispose of any resources that can be recreated.

@IBAction func otherButtonClick(sender: UIButton) {

delegate!.changeLableValue("这是第二个")

self.dismissViewControllerAnimated(true) { () -> Void in

}

class ViewController: UIViewController,ChangeTextDelegate {

func changeLableValue(newString: String) {

lable.text=newString

@IBOutlet weak var lable: UILabel!

@IBOutlet weak var btnClick: UIButton!

@IBAction func buttonClick(sender: UIButton) {

let storyBoard = UIStoryboard(name: "Main",bundle: nil)

let otherVc :OtherVC = storyBoard.instantiateViewControllerWithIdentifier("OtherVC") as! OtherVC

otherVc.delegate=self

self.presentViewController(otherVc,animated: true) { () -> Void in

}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读